diff --git a/queries/orderbook/batch_rewards.sql b/queries/orderbook/batch_rewards.sql index fb78d1b2..1e997d69 100644 --- a/queries/orderbook/batch_rewards.sql +++ b/queries/orderbook/batch_rewards.sql @@ -205,10 +205,10 @@ reward_per_auction as ( -- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth) LEAST( GREATEST( - - {{EPSILON}}, + - {{EPSILON_LOWER}}, surplus + protocol_fee + fee - network_fee_correction - reference_score ), - {{EPSILON}} + execution_cost + {{EPSILON_UPPER}} + execution_cost ) as capped_payment, winning_score, reference_score, diff --git a/src/fetch/payouts.py b/src/fetch/payouts.py index 4724f0ee..0921f2a9 100644 --- a/src/fetch/payouts.py +++ b/src/fetch/payouts.py @@ -1,4 +1,5 @@ """Logic for Post CIP 20 Solver Payout Calculation""" + from __future__ import annotations import logging @@ -22,8 +23,10 @@ from src.pg_client import MultiInstanceDBFetcher from src.utils.print_store import Category -PERIOD_BUDGET_COW = 306646 * 10**18 -QUOTE_REWARD = 9 * 10**18 +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 PROTOCOL_FEE_SAFE = Address("0xB64963f95215FDe6510657e719bd832BB8bb941B") @@ -270,7 +273,13 @@ def extend_payment_df(pdf: DataFrame, converter: TokenConversion) -> DataFrame: pdf["reward_eth"] = pdf["payment_eth"] - pdf["execution_cost_eth"] pdf["reward_cow"] = pdf["reward_eth"].apply(converter.eth_to_token) - secondary_allocation = max(PERIOD_BUDGET_COW - pdf["reward_cow"].sum(), 0) + secondary_allocation = max( + min( + PERIOD_BUDGET_COW - pdf["reward_cow"].sum(), + converter.eth_to_token(CONSISTENCY_REWARD_CAP_ETH), + ), + 0, + ) participation_total = pdf["num_participating_batches"].sum() pdf["secondary_reward_cow"] = ( secondary_allocation * pdf["num_participating_batches"] / participation_total @@ -281,7 +290,10 @@ def extend_payment_df(pdf: DataFrame, converter: TokenConversion) -> DataFrame: # 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"] = float(QUOTE_REWARD) * pdf["num_quotes"] + pdf["quote_reward_cow"] = ( + float(min(QUOTE_REWARD_COW, converter.eth_to_token(QUOTE_REWARD_CAP_ETH))) + * pdf["num_quotes"] + ) for number_col in NUMERICAL_COLUMNS: pdf[number_col] = pandas.to_numeric(pdf[number_col]) diff --git a/src/pg_client.py b/src/pg_client.py index 6854716d..d555305f 100644 --- a/src/pg_client.py +++ b/src/pg_client.py @@ -34,7 +34,8 @@ def get_solver_rewards(self, start_block: str, end_block: str) -> DataFrame: open_query("orderbook/batch_rewards.sql") .replace("{{start_block}}", start_block) .replace("{{end_block}}", end_block) - .replace("{{EPSILON}}", "10000000000000000") + .replace("{{EPSILON_LOWER}}", "10000000000000000") + .replace("{{EPSILON_UPPER}}", "12000000000000000") ) results = [ self.exec_query(query=batch_reward_query, engine=engine) diff --git a/tests/queries/test_batch_rewards.py b/tests/queries/test_batch_rewards.py index f0605711..e6e2db77 100644 --- a/tests/queries/test_batch_rewards.py +++ b/tests/queries/test_batch_rewards.py @@ -31,8 +31,8 @@ def test_get_batch_rewards(self): "payment_eth": [ 9.534313722772278e15, 10.5e15, - 600000000000000.00000, - 10450000000000000.00000, + 6600000000000000.00000, + 12450000000000000.00000, -10000000000000000.00000, 0.00000, ], diff --git a/tests/unit/test_payouts.py b/tests/unit/test_payouts.py index 682187f8..3651685a 100644 --- a/tests/unit/test_payouts.py +++ b/tests/unit/test_payouts.py @@ -13,7 +13,7 @@ TokenConversion, prepare_transfers, RewardAndPenaltyDatum, - QUOTE_REWARD, + QUOTE_REWARD_COW, PROTOCOL_FEE_SAFE, ) from src.models.accounting_period import AccountingPeriod @@ -110,22 +110,22 @@ def test_extend_payment_df(self): 0, ], "secondary_reward_cow": [ - 97569245454545450000000.00000, - 27876927272727270000000.00000, - 97569245454545450000000.00000, - 83630781818181820000000.00000, + 1909090909090909000000.00000, + 545454545454545440000.00000, + 1909090909090909000000.00000, + 1636363636363636200000.00000, ], "secondary_reward_eth": [ - 97569245454545450000.00000, - 27876927272727273000.00000, - 97569245454545450000.00000, - 83630781818181810000.00000, + 1909090909090909000.00000, + 545454545454545440.00000, + 1909090909090909000.00000, + 1636363636363636200.00000, ], "quote_reward_cow": [ 0.00000, 0.00000, - 90000000000000000000.00000, - 180000000000000000000.00000, + 6000000000000000000.00000, + 12000000000000000000.00000, ], } expected = DataFrame(expected_data_dict) @@ -244,22 +244,22 @@ def test_construct_payouts(self): 0, ], "secondary_reward_cow": [ - 97569245454545450000000.00000, - 27876927272727270000000.00000, - 97569245454545450000000.00000, - 83630781818181820000000.00000, + 1909090909090909000000.00000, + 545454545454545440000.00000, + 1909090909090909000000.00000, + 1636363636363636200000.00000, ], "secondary_reward_eth": [ - 97569245454545450000.00000, - 27876927272727273000.00000, - 97569245454545450000.00000, - 83630781818181810000.00000, + 1909090909090909000.00000, + 545454545454545440.00000, + 1909090909090909000.00000, + 1636363636363636200.00000, ], "quote_reward_cow": [ 0.00000, 0.00000, - 90000000000000000000.00000, - 180000000000000000000.00000, + 6000000000000000000.00000, + 12000000000000000000.00000, ], "solver_name": ["S_1", "S_2", "S_3", None], "eth_slippage_wei": [1.0, 0.0, -1.0, None], @@ -401,7 +401,7 @@ def sample_record( secondary_reward_eth=participation, secondary_reward_cow=participation * self.conversion_rate, slippage_eth=slippage, - quote_reward_cow=QUOTE_REWARD * num_quotes, + quote_reward_cow=QUOTE_REWARD_COW * num_quotes, ) def test_invalid_input(self):