Skip to content

Commit

Permalink
add some assertions for dataframes before merging
Browse files Browse the repository at this point in the history
  • Loading branch information
harisang committed Oct 24, 2024
1 parent fa1e14a commit d58cc4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/fetch/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,16 @@ def construct_payouts(
]
service_fee_df = service_fee_df[["solver", "service_fee"]]

# check if all solvers receiving rewards have an associated service fee status
service_fee_df_solvers = []
for _, row in service_fee_df.iterrows():
service_fee_df_solvers.append(row["solver"])
for _, row in merged_df.iterrows():
solver = row["solver"]
assert (
solver in service_fee_df_solvers
), "Solver service fee status undefinded " + str(solver)

complete_payout_df = construct_payout_dataframe(
# Fetch and extend auction data from orderbook.
payment_df=extend_payment_df(
Expand Down
24 changes: 20 additions & 4 deletions src/pg_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,16 @@ def get_solver_rewards(self, start_block: str, end_block: str) -> DataFrame:
results.append(
self.exec_query(query=batch_reward_query_barn, engine=engine)
)

return pd.concat(results)
result = pd.concat(results)
# check for duplicate solver entries and raise an error if there are any duplicates
solvers = []
for _, row in result.iterrows():
solver = row["solver"]
assert (
solver not in solvers
), "Solver for batch rewards appears in both prod and barn " + str(solver)
solvers.append(solver)
return result

def get_quote_rewards(self, start_block: str, end_block: str) -> DataFrame:
"""Returns aggregated solver quote rewards for block range"""
Expand All @@ -70,8 +78,16 @@ def get_quote_rewards(self, start_block: str, end_block: str) -> DataFrame:
self.exec_query(query=quote_reward_query, engine=engine)
for engine in self.connections
]

return pd.concat(results)
result = pd.concat(results)
# check for duplicate solver entries and raise an error if there are any duplicates
solvers = []
for _, row in result.iterrows():
solver = row["solver"]
assert (
solver not in solvers
), "Solver for quote rewards appears in both prod and barn " + str(solver)
solvers.append(solver)
return result


def pg_hex2bytea(hex_address: str) -> str:
Expand Down

0 comments on commit d58cc4e

Please sign in to comment.