Skip to content

Commit

Permalink
Use new service fee query (#433)
Browse files Browse the repository at this point in the history
This PR updates the query id that is used for computing whether a
service fee should be applied. Some minor simplifications in the code
are needed.

This PR should be merged only after this dune-queries has been properly
reviewed: cowprotocol/dune-queries#66
  • Loading branch information
harisang authored Nov 21, 2024
1 parent 5f6bc09 commit 8f52179
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/fetch/dune.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def get_service_fee_status(self) -> list[DuneRecord]:
return self._get_query_results(
query=self._parameterized_query(
query_data=QUERIES["SERVICE_FEE_STATUS"],
params=[],
params=[
QueryParameter.date_type("start_time", self.period.start),
QueryParameter.date_type("end_time", self.period.end),
],
)
)
15 changes: 4 additions & 11 deletions src/fetch/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import math
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import timedelta
from fractions import Fraction
from typing import Callable

Expand Down Expand Up @@ -437,13 +437,6 @@ def construct_payout_dataframe(
config.reward_config.reward_token_address.address
)

# 7. Missing service fee is treated as new solver
if any(merged_df["service_fee"].isna()):
missing_solvers = merged_df["solver"].loc[merged_df["service_fee"].isna()]
logging.warning(
f"Solvers {missing_solvers} without service fee info. Using 0%. "
f"Check service fee query."
)
merged_df["service_fee"] = merged_df["service_fee"].fillna(Fraction(0, 1)) # type: ignore

return merged_df
Expand Down Expand Up @@ -518,10 +511,10 @@ def construct_payouts(

service_fee_df = pandas.DataFrame(dune.get_service_fee_status())
service_fee_df["service_fee"] = [
(datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S.%f %Z") <= dune.period.start)
* config.reward_config.service_fee_factor
for time_string in service_fee_df["expires"]
service_fee_flag * config.reward_config.service_fee_factor
for service_fee_flag in service_fee_df["service_fee"]
]

reward_target_df = pandas.DataFrame(dune.get_vouches())
# construct slippage df
if ignore_slippage_flag or (not config.buffer_accounting_config.include_slippage):
Expand Down
2 changes: 1 addition & 1 deletion src/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def with_params(self, params: list[QueryParameter]) -> QueryBase:
),
"SERVICE_FEE_STATUS": QueryData(
name="CIP-48 Service fee status",
q_id=4017925,
q_id=4298142,
),
"PERIOD_SLIPPAGE": QueryData(
name="Solver Slippage for Period",
Expand Down

0 comments on commit 8f52179

Please sign in to comment.