Skip to content

Commit

Permalink
Remove consistency rewards and dune parameters cleanup and fixing (#395)
Browse files Browse the repository at this point in the history
As part of cleaning up and restructuring some Dune queries (see relevant
PRs [here](https://github.com/cowprotocol/dune-queries/pulls)), some
parameters needed to be dropped or renamed. This branch is what we used
to run the script for the payouts of Sep 3-10, 2024.

Moreover, we decided to remove consistency rewards altogether from the
main script, as we are moving away from those and it doesn't seem likely
that they will come back. Note however that the main sql query that
computes rewards, one of the core components of the script, is not
changed and consistency rewards are still computed there. This will be
addressed in a follow-up PR as that query is an important part of the
script and thus we thought it is better to address it separately.
  • Loading branch information
harisang authored Sep 17, 2024
1 parent e91fd75 commit 3d733da
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 173 deletions.
9 changes: 0 additions & 9 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,3 @@

# Real Web3 Instance
web3 = Web3(Web3.HTTPProvider(NODE_URL))

RECOGNIZED_BONDING_POOLS = [
"('0x8353713b6D2F728Ed763a04B886B16aAD2b16eBD', 'Gnosis', "
"'0x6c642cafcbd9d8383250bb25f67ae409147f78b2')",
"('0x5d4020b9261F01B6f8a45db929704b0Ad6F5e9E6', 'CoW Services', "
"'0x423cec87f19f0778f549846e0801ee267a917935')",
"('0xC96569Dc132ebB6694A5f0b781B33f202Da8AcE8', 'Project Blanc', "
"'0xCa99e3Fc7B51167eaC363a3Af8C9A185852D1622')",
]
26 changes: 5 additions & 21 deletions src/fetch/dune.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from dune_client.query import QueryBase
from dune_client.types import QueryParameter, DuneRecord

from src.constants import RECOGNIZED_BONDING_POOLS
from src.fetch.token_list import get_trusted_tokens
from src.logger import set_log
from src.models.accounting_period import AccountingPeriod
from src.queries import QUERIES, QueryData
Expand Down Expand Up @@ -85,14 +83,12 @@ def get_vouches(self) -> list[DuneRecord]:
"""
Fetches & Returns Parsed Results for VouchRegistry query.
"""
pool_values = ",\n".join(RECOGNIZED_BONDING_POOLS)
return self._get_query_results(
query=self._parameterized_query(
query_data=QUERIES["VOUCH_REGISTRY"],
params=[
QueryParameter.date_type("EndTime", self.period.end),
QueryParameter.text_type("BondingPoolData", pool_values),
QueryParameter.enum_type("VOUCH_CTE_NAME", "valid_vouches"),
QueryParameter.date_type("end_time", self.period.end),
QueryParameter.enum_type("vouch_cte_name", "valid_vouches"),
],
)
)
Expand All @@ -102,24 +98,15 @@ def get_period_slippage(self, job_id: Optional[str] = None) -> list[DuneRecord]:
Executes & Fetches results of slippage query per solver for specified accounting period.
Returns a class representation of the results as two lists (positive & negative).
"""
token_list = get_trusted_tokens()
params = self._period_params() + [
QueryParameter.text_type("TxHash", "0x"),
QueryParameter.text_type("TokenList", ",".join(token_list)),
]
params = self._period_params()
# trigger dashboard update
self.dune.execute(
self._parameterized_query(QUERIES["DASHBOARD_SLIPPAGE"], params=params)
)

return self._get_query_results(
self._parameterized_query(
QUERIES["PERIOD_SLIPPAGE"],
params=self._period_params()
+ [
QueryParameter.text_type("TxHash", "0x"),
QueryParameter.text_type("TokenList", ",".join(token_list)),
],
QUERIES["PERIOD_SLIPPAGE"], params=self._period_params()
),
job_id,
)
Expand All @@ -128,12 +115,9 @@ def get_service_fee_status(self) -> list[DuneRecord]:
"""
Fetches & Returns Parsed Results for VouchRegistry query.
"""
pool_values = ",\n".join(RECOGNIZED_BONDING_POOLS)
return self._get_query_results(
query=self._parameterized_query(
query_data=QUERIES["SERVICE_FEE_STATUS"],
params=[
QueryParameter.text_type("BondingPoolData", pool_values),
],
params=[],
)
)
53 changes: 5 additions & 48 deletions src/fetch/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from src.pg_client import MultiInstanceDBFetcher
from src.utils.print_store import Category

PERIOD_BUDGET_COW = 250000 * 10**18
CONSISTENCY_REWARD_CAP_ETH = 6 * 10**18
QUOTE_REWARD_COW = 6 * 10**18
QUOTE_REWARD_CAP_ETH = 6 * 10**14
SERVICE_FEE_FACTOR = Fraction(15, 100)
Expand All @@ -35,8 +33,6 @@
"solver",
"primary_reward_eth",
"primary_reward_cow",
"secondary_reward_eth",
"secondary_reward_cow",
"quote_reward_cow",
"protocol_fee_eth",
"network_fee_eth",
Expand All @@ -53,8 +49,6 @@
NUMERICAL_COLUMNS = [
"primary_reward_eth",
"primary_reward_cow",
"secondary_reward_cow",
"secondary_reward_eth",
"quote_reward_cow",
"protocol_fee_eth",
]
Expand All @@ -81,15 +75,12 @@ def __init__( # pylint: disable=too-many-arguments
reward_target: Address,
bonding_pool: Address,
primary_reward_eth: int,
secondary_reward_eth: int,
slippage_eth: int,
primary_reward_cow: int,
secondary_reward_cow: int,
quote_reward_cow: int,
service_fee: bool,
):
assert secondary_reward_eth >= 0, "invalid secondary_reward_eth"
assert secondary_reward_cow >= 0, "invalid secondary_reward_cow"

assert quote_reward_cow >= 0, "invalid quote_reward_cow"

self.solver = solver
Expand All @@ -99,8 +90,6 @@ def __init__( # pylint: disable=too-many-arguments
self.slippage_eth = slippage_eth
self.primary_reward_eth = primary_reward_eth
self.primary_reward_cow = primary_reward_cow
self.secondary_reward_eth = secondary_reward_eth
self.secondary_reward_cow = secondary_reward_cow
self.quote_reward_cow = quote_reward_cow
self.service_fee = service_fee

Expand All @@ -114,7 +103,7 @@ def from_series(cls, frame: Series) -> RewardAndPenaltyDatum:
)
solver = frame["solver"]
reward_target = frame["reward_target"]
bonding_pool = frame["pool"]
bonding_pool = frame["pool_address"]
if reward_target is None:
logging.warning(f"solver {solver} without reward_target. Using solver")
reward_target = solver
Expand All @@ -127,8 +116,6 @@ def from_series(cls, frame: Series) -> RewardAndPenaltyDatum:
slippage_eth=slippage,
primary_reward_eth=int(frame["primary_reward_eth"]),
primary_reward_cow=int(frame["primary_reward_cow"]),
secondary_reward_eth=int(frame["secondary_reward_eth"]),
secondary_reward_cow=int(frame["secondary_reward_cow"]),
quote_reward_cow=int(frame["quote_reward_cow"]),
service_fee=bool(frame["service_fee"]),
)
Expand All @@ -139,17 +126,11 @@ def total_outgoing_eth(self) -> int:

def total_cow_reward(self) -> int:
"""Total outgoing COW token reward"""
return int(
self.reward_scaling()
* (self.primary_reward_cow + self.secondary_reward_cow)
)
return int(self.reward_scaling() * self.primary_reward_cow)

def total_eth_reward(self) -> int:
"""Total outgoing ETH reward"""
return int(
self.reward_scaling()
* (self.primary_reward_eth + self.secondary_reward_eth)
)
return int(self.reward_scaling() * self.primary_reward_eth)

def reward_scaling(self) -> Fraction:
"""Scaling factor for service fee
Expand Down Expand Up @@ -198,7 +179,7 @@ def as_payouts(self) -> list[Transfer]:
# Note that;
# reimbursement_eth + reward_eth
# = self.total_eth_reward() + self.exec_cost + self.slippage_eth
# = self.payment_eth + self.secondary_reward_eth + self.slippage_eth
# = self.payment_eth + self.slippage_eth
# = self.total_outgoing_eth()
# >= 0 (because not self.is_overdraft())
try:
Expand Down Expand Up @@ -288,32 +269,10 @@ def extend_payment_df(pdf: DataFrame, converter: TokenConversion) -> DataFrame:
Extending the basic columns returned by SQL Query with some after-math:
- reward_eth as difference of payment and execution_cost
- reward_cow as conversion from ETH to cow.
- secondary_reward (as the remaining reward after all has been distributed)
This is evaluated in both ETH and COW (for different use cases).
"""
# Note that this can be negative!
pdf["primary_reward_cow"] = pdf["primary_reward_eth"].apply(converter.eth_to_token)

secondary_allocation = max(
min(
PERIOD_BUDGET_COW - pdf["primary_reward_cow"].sum(),
converter.eth_to_token(CONSISTENCY_REWARD_CAP_ETH),
),
0,
)
participation_total = pdf["num_participating_batches"].sum()
if participation_total == 0:
# Due to CIP-48 we will stop counting participation. This workaround avoids
# division by zero as the num_participation_batches is set to zero for all
# solvers after CIP-48.
participation_total = 1
pdf["secondary_reward_cow"] = (
secondary_allocation * pdf["num_participating_batches"] / participation_total
)
pdf["secondary_reward_eth"] = pdf["secondary_reward_cow"].apply(
converter.token_to_eth
)

# Pandas has poor support for large integers, must cast the constant to float here,
# otherwise the dtype would be inferred as int64 (which overflows).
pdf["quote_reward_cow"] = (
Expand Down Expand Up @@ -545,13 +504,11 @@ def construct_payouts(
partner_fee_tax_wei = total_partner_fee_wei_untaxed - total_partner_fee_wei_taxed

performance_reward = complete_payout_df["primary_reward_cow"].sum()
participation_reward = complete_payout_df["secondary_reward_cow"].sum()
quote_reward = complete_payout_df["quote_reward_cow"].sum()

dune.log_saver.print(
"Payment breakdown (ignoring service fees):\n"
f"Performance Reward: {performance_reward / 10 ** 18:.4f}\n"
f"Participation Reward: {participation_reward / 10 ** 18:.4f}\n"
f"Quote Reward: {quote_reward / 10 ** 18:.4f}\n"
f"Protocol Fees: {final_protocol_fee_wei / 10 ** 18:.4f}\n"
f"Partner Fees Tax: {partner_fee_tax_wei / 10 ** 18:.4f}\n"
Expand Down
4 changes: 2 additions & 2 deletions src/models/accounting_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def __hash__(self) -> int:
def as_query_params(self) -> list[QueryParameter]:
"""Returns commonly used (StartTime, EndTime) query parameters"""
return [
QueryParameter.date_type("StartTime", self.start),
QueryParameter.date_type("EndTime", self.end),
QueryParameter.date_type("start_time", self.start),
QueryParameter.date_type("end_time", self.end),
]

def dashboard_url(self) -> str:
Expand Down
Loading

0 comments on commit 3d733da

Please sign in to comment.