Skip to content

Commit

Permalink
Merge branch 'main' into remove_dead_code
Browse files Browse the repository at this point in the history
  • Loading branch information
harisang authored Nov 4, 2024
2 parents 15b4856 + a196e0c commit 8e90606
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
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]
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 @@ -480,7 +487,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 @@ -493,11 +515,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
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,
)

0 comments on commit 8e90606

Please sign in to comment.