Skip to content

Commit

Permalink
[Tech Debt] Remove Old Dead Code (pre CIP-20) (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Jul 10, 2023
1 parent 3bd9ccb commit c34757e
Show file tree
Hide file tree
Showing 24 changed files with 20 additions and 1,528 deletions.
12 changes: 0 additions & 12 deletions queries/dune_v2/eth_spent.sql

This file was deleted.

51 changes: 0 additions & 51 deletions queries/dune_v2/risk_free_batches.sql

This file was deleted.

8 changes: 0 additions & 8 deletions queries/dune_v2/trade_counts.sql

This file was deleted.

31 changes: 0 additions & 31 deletions queries/orderbook/order_rewards.sql

This file was deleted.

7 changes: 7 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@

# Real Web3 Instance
web3 = Web3(Web3.HTTPProvider(NODE_URL))

RECOGNIZED_BONDING_POOLS = [
"('0x8353713b6D2F728Ed763a04B886B16aAD2b16eBD', 'Gnosis', "
"'0x6c642cafcbd9d8383250bb25f67ae409147f78b2')",
"('0x5d4020b9261F01B6f8a45db929704b0Ad6F5e9E6', 'CoW Services', "
"'0x423cec87f19f0778f549846e0801ee267a917935')",
]
47 changes: 0 additions & 47 deletions src/fetch/cow_rewards.py

This file was deleted.

86 changes: 3 additions & 83 deletions src/fetch/dune.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
"""All Dune related query fetching is defined here in the DuneFetcherClass"""
from typing import Optional

import pandas as pd
from dune_client.client import DuneClient
from dune_client.query import Query
from dune_client.types import QueryParameter, DuneRecord

from src.fetch.cow_rewards import aggregate_orderbook_rewards
from src.constants import RECOGNIZED_BONDING_POOLS
from src.fetch.token_list import get_trusted_tokens
from src.logger import set_log
from src.models.accounting_period import AccountingPeriod
from src.models.slippage import SplitSlippages
from src.models.split_transfers import SplitTransfers
from src.models.transfer import Transfer
from src.models.vouch import RECOGNIZED_BONDING_POOLS, parse_vouches
from src.pg_client import DualEnvDataframe
from src.queries import QUERIES, QueryData
from src.utils.print_store import PrintStore, Category

Expand Down Expand Up @@ -48,8 +42,9 @@ def _period_params(self) -> list[QueryParameter]:
"""Easier access to these parameters."""
return self.period.as_query_params()

@staticmethod
def _parameterized_query(
self, query_data: QueryData, params: list[QueryParameter]
query_data: QueryData, params: list[QueryParameter]
) -> Query:
return query_data.with_params(params)

Expand Down Expand Up @@ -85,66 +80,6 @@ def get_block_interval(self) -> tuple[str, str]:
assert len(results) == 1, "Block Interval Query should return only 1 result!"
return str(results[0]["start_block"]), str(results[0]["end_block"])

def get_eth_spent(self) -> list[Transfer]:
"""
Fetches ETH spent on successful settlements by all solvers during `period`
"""
results = self._get_query_results(
self._parameterized_query(QUERIES["ETH_SPENT"], self._period_params())
)
return [Transfer.from_dict(t) for t in results]

def get_risk_free_batches(self) -> set[str]:
"""Fetches Risk Free Batches from Dune"""
results = self._get_query_results(
self._parameterized_query(
QUERIES["RISK_FREE_BATCHES"], self._period_params()
)
)
return {row["tx_hash"].lower() for row in results}

def get_trade_counts(self) -> list[DuneRecord]:
"""Fetches Trade Counts for Period"""
return self._get_query_results(
query=self._parameterized_query(
query_data=QUERIES["TRADE_COUNT"],
params=[
QueryParameter.text_type("start_block", self.start_block),
QueryParameter.text_type("end_block", self.end_block),
],
)
)

def get_cow_rewards(self) -> list[Transfer]:
"""
Fetches COW token rewards from orderbook database returning a list of Transfers
"""
print(
f"Fetching CoW Rewards for block interval {self.start_block}, {self.end_block}"
)
per_order_df = DualEnvDataframe.get_orderbook_rewards(
self.start_block, self.end_block
)
cow_rewards_df = aggregate_orderbook_rewards(
per_order_df,
risk_free_transactions=self.get_risk_free_batches(),
)

# Validation of results - using characteristics of results from two sources.
trade_counts = self.get_trade_counts()
# Number of trades per solver retrieved from orderbook agrees ethereum events.
duplicates = pd.concat(
[
pd.DataFrame(trade_counts),
cow_rewards_df[["receiver", "num_trades"]].rename(
columns={"receiver": "solver"}
),
]
).drop_duplicates(keep=False)

assert len(duplicates) == 0, f"solver sets disagree: {duplicates}"
return Transfer.from_dataframe(cow_rewards_df)

def get_vouches(self) -> list[DuneRecord]:
"""
Fetches & Returns Parsed Results for VouchRegistry query.
Expand Down Expand Up @@ -187,18 +122,3 @@ def get_period_slippage(self, job_id: Optional[str] = None) -> list[DuneRecord]:
),
job_id,
)

def get_transfers(self) -> list[Transfer]:
"""Fetches and returns slippage-adjusted Transfers for solver reimbursement"""
# TODO - fetch these three results asynchronously!
reimbursements = self.get_eth_spent()
rewards = self.get_cow_rewards()
split_transfers = SplitTransfers(
period=self.period,
mixed_transfers=reimbursements + rewards,
log_saver=self.log_saver,
)
return split_transfers.process(
slippages=SplitSlippages.from_data_set(self.get_period_slippage()),
cow_redirects=parse_vouches(self.get_vouches()),
)
2 changes: 1 addition & 1 deletion src/fetch/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def construct_payout_dataframe(
return merged_df


def post_cip20_payouts(
def construct_payouts(
dune: DuneFetcher, orderbook: MultiInstanceDBFetcher
) -> list[Transfer]:
"""Workflow of solver reward payout logic post-CIP20"""
Expand Down
21 changes: 8 additions & 13 deletions src/fetch/transfer_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
FILE_OUT_DIR,
DOCS_URL,
)
from src.fetch.payouts import post_cip20_payouts
from src.fetch.payouts import construct_payouts
from src.models.accounting_period import AccountingPeriod
from src.models.transfer import Transfer, CSVTransfer
from src.multisend import post_multisend, prepend_unwrap_if_necessary
Expand Down Expand Up @@ -108,18 +108,13 @@ def auto_propose(
category=Category.GENERAL,
)

if args.pre_cip20:
payout_transfers = dune.get_transfers()
Transfer.sort_list(payout_transfers)

else:
payout_transfers = post_cip20_payouts(
args.dune,
orderbook=MultiInstanceDBFetcher(
[os.environ["PROD_DB_URL"], os.environ["BARN_DB_URL"]]
),
)

payout_transfers = construct_payouts(
args.dune,
orderbook=MultiInstanceDBFetcher(
[os.environ["PROD_DB_URL"], os.environ["BARN_DB_URL"]]
),
)
Transfer.sort_list(payout_transfers)
payout_transfers = list(
filter(
lambda payout: payout.amount_wei > args.min_transfer_amount_wei,
Expand Down
19 changes: 0 additions & 19 deletions src/models/overdraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
from dune_client.types import Address

from src.models.accounting_period import AccountingPeriod
from src.models.slippage import SolverSlippage
from src.models.token import TokenType
from src.models.transfer import Transfer


@dataclass
Expand All @@ -23,22 +20,6 @@ class Overdraft:
name: str
wei: int

@classmethod
def from_objects(
cls, transfer: Transfer, slippage: SolverSlippage, period: AccountingPeriod
) -> Overdraft:
"""Constructs an overdraft instance based on Transfer & Slippage"""
assert transfer.recipient == slippage.solver_address
assert transfer.token_type == TokenType.NATIVE
overdraft = transfer.amount_wei + slippage.amount_wei
assert overdraft < 0, "This is why we are here."
return cls(
period=period,
name=slippage.solver_name,
account=slippage.solver_address,
wei=abs(overdraft),
)

@property
def eth(self) -> float:
"""Returns amount in units"""
Expand Down
16 changes: 0 additions & 16 deletions src/models/period_totals.py

This file was deleted.

Loading

0 comments on commit c34757e

Please sign in to comment.