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

Add flag to skip slippage computations #407

Merged
merged 9 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ options:
Ignore ETH transfers with amount less than this
--min-transfer-amount-cow-atoms MIN_TRANSFER_AMOUNT_COW_ATOMS
Ignore COW transfers with amount less than this
--ignore-slippage IGNORE_SLIPPAGE
Ignore slippage computations
```

The solver reimbursements are executed each Tuesday with the accounting period of the last 7 days.
Expand Down
2 changes: 1 addition & 1 deletion src/fetch/dune.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_vouches(self) -> list[DuneRecord]:
query_data=QUERIES["VOUCH_REGISTRY"],
params=[
QueryParameter.date_type("end_time", self.period.end),
QueryParameter.enum_type("vouch_cte_name", "valid_vouches"),
QueryParameter.enum_type("vouch_cte_name", "named_results"),
],
)
)
Expand Down
39 changes: 30 additions & 9 deletions src/fetch/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,6 @@ def construct_payout_dataframe(
Namely, reward targets and slippage (coming from Dune)
with reward and execution data coming from orderbook.
"""
# TODO - After CIP-20 phased in, adapt query to return `solver` like all the others
slippage_df = slippage_df.rename(columns={"solver_address": "solver"})
# 1. Assert existence of required columns.
validate_df_columns(payment_df, slippage_df, reward_target_df, service_fee_df)

Expand All @@ -401,10 +399,19 @@ def construct_payout_dataframe(
normalize_address_field(service_fee_df, join_column)

# 3. Merge the three dataframes (joining on solver)

reward_target_reduced_df_columns = [
x for x in list(reward_target_df.columns) if x != "solver_name"
]
reward_target_reduced_df = reward_target_df[reward_target_reduced_df_columns]
service_fee_reduced_df_columns = [
x for x in list(service_fee_df.columns) if x != "solver_name"
]
service_fee_reduced_df = service_fee_df[service_fee_reduced_df_columns]
Comment on lines +403 to +410
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that we are not really interested in the fully general approach. Then this would work:

Suggested change
reward_target_reduced_df_columns = [
x for x in list(reward_target_df.columns) if x != "solver_name"
]
reward_target_reduced_df = reward_target_df[reward_target_reduced_df_columns]
service_fee_reduced_df_columns = [
x for x in list(service_fee_df.columns) if x != "solver_name"
]
service_fee_reduced_df = service_fee_df[service_fee_reduced_df_columns]
reward_target_reduced_df = reward_target_df.drop("solver_name", axis=1)
service_fee_reduced_df = service_fee_df.drop("solver_name", axis=1)

If we actually want that generality, this and other data transformations should probably happen somewhere else. E.g. right after fetching the data.

merged_df = (
payment_df.merge(slippage_df, on=join_column, how="left")
.merge(reward_target_df, on=join_column, how="left")
.merge(service_fee_df, on=join_column, how="left")
.merge(reward_target_reduced_df, on=join_column, how="left")
.merge(service_fee_reduced_df, on=join_column, how="left")
)

# 4. Add slippage from fees to slippage
Expand Down Expand Up @@ -454,7 +461,7 @@ def construct_partner_fee_payments(


def construct_payouts(
dune: DuneFetcher, orderbook: MultiInstanceDBFetcher
dune: DuneFetcher, ignore_slippage_flag: bool, orderbook: MultiInstanceDBFetcher
) -> list[Transfer]:
"""Workflow of solver reward payout logic post-CIP27"""
# pylint: disable-msg=too-many-locals
Expand All @@ -476,7 +483,22 @@ def construct_payouts(
datetime.strptime(time_string, "%Y-%m-%d %H:%M:%S.%f %Z") <= dune.period.start
for time_string in service_fee_df["expires"]
]
service_fee_df = service_fee_df[["solver", "service_fee"]]
reward_target_df = pandas.DataFrame(dune.get_vouches())
# construct slippage df
if ignore_slippage_flag:
slippage_df_temp = pandas.merge(
merged_df[["solver"]],
reward_target_df[["solver", "solver_name"]],
on="solver",
how="inner",
)
slippage_df = slippage_df_temp.assign(
eth_slippage_wei=[0] * slippage_df_temp.shape[0]
)
else:
slippage_df = pandas.DataFrame(dune.get_period_slippage())
# TODO - After CIP-20 phased in, adapt query to return `solver` like all the others
slippage_df = slippage_df.rename(columns={"solver_address": "solver"})

complete_payout_df = construct_payout_dataframe(
# Fetch and extend auction data from orderbook.
Expand All @@ -489,11 +511,10 @@ def construct_payouts(
),
),
# Dune: Fetch Solver Slippage & Reward Targets
slippage_df=pandas.DataFrame(dune.get_period_slippage()),
reward_target_df=pandas.DataFrame(dune.get_vouches()),
slippage_df=slippage_df,
reward_target_df=reward_target_df,
service_fee_df=service_fee_df,
)

# Sort by solver before breaking this data frame into Transfer objects.
complete_payout_df = complete_payout_df.sort_values("solver")

Expand Down
1 change: 1 addition & 0 deletions src/fetch/transfer_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def auto_propose(

payout_transfers_temp = construct_payouts(
args.dune,
args.ignore_slippage,
orderbook=MultiInstanceDBFetcher(
[os.environ["PROD_DB_URL"], os.environ["BARN_DB_URL"]]
),
Expand Down
2 changes: 1 addition & 1 deletion src/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def with_params(self, params: list[QueryParameter]) -> QueryBase:
),
"PERIOD_SLIPPAGE": QueryData(
name="Solver Slippage for Period",
q_id=3427730,
q_id=4070065,
),
"DASHBOARD_SLIPPAGE": QueryData(
name="Period Solver Rewards",
Expand Down
8 changes: 8 additions & 0 deletions src/utils/script_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ScriptArgs:
consolidate_transfers: bool
min_transfer_amount_wei: int
min_transfer_amount_cow_atoms: int
ignore_slippage: bool


def generic_script_init(description: str) -> ScriptArgs:
Expand Down Expand Up @@ -70,6 +71,12 @@ def generic_script_init(description: str) -> ScriptArgs:
help="Ignore COW transfers with amount less than this",
default=20000000000000000000,
)
parser.add_argument(
"--ignore-slippage",
type=bool,
help="Flag for ignoring slippage computations",
default=False,
)
args = parser.parse_args()
return ScriptArgs(
dune=DuneFetcher(
Expand All @@ -81,4 +88,5 @@ def generic_script_init(description: str) -> ScriptArgs:
consolidate_transfers=args.consolidate_transfers,
min_transfer_amount_wei=args.min_transfer_amount_wei,
min_transfer_amount_cow_atoms=args.min_transfer_amount_cow_atoms,
ignore_slippage=args.ignore_slippage,
)
Loading