Skip to content

Commit

Permalink
Implement CIP-36 (#339)
Browse files Browse the repository at this point in the history
[CIP-36](https://snapshot.org/#/cow.eth/proposal/0x4e58f9c1208121c0e06282b5541b458bc8c8b76090263e25448848f3194df986)
changed the capping of rewards:
- Rewards are capped asymmetrically with an upper bound changed from
0.01ETH to 0.012ETH.
- The soft budget for rewards was changed from 306,645 COW to 250,000
COW.
- Consistency rewards are capped at 6ETH worth of COW tokens.
- Quoter rewards are the minumum of 6 COW and 0.0006 ETH worth of COW
per quote.

This PR implements these changes. These changes need be implemented in
dune-sync and on dune as well.

The scripts in this PR need to be used for the next payment.
  • Loading branch information
fhenneke authored Feb 8, 2024
1 parent 78cbc31 commit 1a00c85
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 31 deletions.
4 changes: 2 additions & 2 deletions queries/orderbook/batch_rewards.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 16 additions & 4 deletions src/fetch/payouts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Logic for Post CIP 20 Solver Payout Calculation"""

from __future__ import annotations

import logging
Expand All @@ -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")

Expand Down Expand Up @@ -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
Expand All @@ -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])
Expand Down
3 changes: 2 additions & 1 deletion src/pg_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/queries/test_batch_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
44 changes: 22 additions & 22 deletions tests/unit/test_payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TokenConversion,
prepare_transfers,
RewardAndPenaltyDatum,
QUOTE_REWARD,
QUOTE_REWARD_COW,
PROTOCOL_FEE_SAFE,
)
from src.models.accounting_period import AccountingPeriod
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 1a00c85

Please sign in to comment.