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

[Draft] Restructure payouts #435

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
39 changes: 39 additions & 0 deletions src/fetch/buffer_accounting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
"""Functionality for buffer accounting."""

from pandas import DataFrame

BATCH_DATA_COLUMNS = ["solver", "network_fee_eth"]
SLIPPAGE_COLUMNS = [
"solver",
"eth_slippage_wei",
]

BUFFER_ACCOUNTING_COLUMNS = [
"solver",
"network_fee_eth",
"slippage_eth",
]


def compute_buffer_accounting(
batch_data: DataFrame, slippage_data: DataFrame
) -> DataFrame:
"""Compute buffer accounting per solver"""

# validate batch rewards and quote rewards columns
assert set(BATCH_DATA_COLUMNS).issubset(set(batch_data.columns))
assert set(SLIPPAGE_COLUMNS).issubset(set(slippage_data.columns))

buffer_accounting = batch_data[BATCH_DATA_COLUMNS].merge(
slippage_data[SLIPPAGE_COLUMNS], how="outer", on="solver", validate="one_to_one"
)
buffer_accounting = buffer_accounting.rename(
columns={"eth_slippage_wei": "slippage_eth"}
)

# change all types to object to use native python types
buffer_accounting = buffer_accounting.astype(object)

assert set(buffer_accounting.columns) == set(BUFFER_ACCOUNTING_COLUMNS)

return buffer_accounting
62 changes: 62 additions & 0 deletions src/fetch/partner_fees.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Functionality for partner fees."""

from collections import defaultdict

import numpy as np
import pandas as pd
from pandas import DataFrame

from src.config import ProtocolFeeConfig

BATCH_DATA_COLUMNS = ["partner_list", "partner_fee_eth"]

PARTNER_FEES_COLUMNS = ["partner", "partner_fee_eth", "partner_fee_tax"]


def compute_partner_fees(batch_data: DataFrame, config: ProtocolFeeConfig) -> DataFrame:
"""Compute partner fees per integrator"""

# validate batch rewards and quote rewards columns
assert set(BATCH_DATA_COLUMNS).issubset(set(batch_data.columns))

partner_fee_lists = batch_data[BATCH_DATA_COLUMNS]

partner_fees = compute_partner_fees_per_partner(partner_fee_lists, config)

return partner_fees


def compute_partner_fees_per_partner(
partner_fee_lists: DataFrame, config: ProtocolFeeConfig
) -> DataFrame:
"""Aggregate fees from different solvers"""

partner_fees_dict: defaultdict[str, int] = defaultdict(int)
for _, row in partner_fee_lists.iterrows():
if row["partner_list"] is None:
continue

# We assume the two lists used below, i.e.,
# partner_list and partner_fee_eth,
# are "aligned".

for partner, partner_fee in zip(row["partner_list"], row["partner_fee_eth"]):
partner_fees_dict[partner] += int(partner_fee)

partner_fees_df = pd.DataFrame(
list(partner_fees_dict.items()),
columns=["partner", "partner_fee_eth"],
)

partner_fees_df["partner_fee_tax"] = np.where(
partner_fees_df["partner"] == config.reduced_cut_address,
config.partner_fee_reduced_cut,
config.partner_fee_cut,
)

# change all types to object to use native python types
partner_fees_df = partner_fees_df.astype(object)

assert set(partner_fees_df.columns) == set(PARTNER_FEES_COLUMNS)

return partner_fees_df
Loading
Loading