Skip to content

Commit

Permalink
Merge pull request #104 from cowprotocol/reward_from_scores
Browse files Browse the repository at this point in the history
[Mirror] Use scores instead of surplus for reward computation
  • Loading branch information
harisang authored Jul 12, 2024
2 parents b778238 + 612bf72 commit d3b054d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/sql/orderbook/barn_batch_rewards.sql
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ reward_data AS (
end as fee,
-- scores
winning_score,
case
when block_number is not null
and block_number <= block_deadline then winning_score
else 0
end as observed_score,
reference_score,
-- auction_participation
participating_solvers,
Expand Down Expand Up @@ -390,12 +395,12 @@ reward_per_auction as (
surplus,
protocol_fee, -- the protocol fee
fee - network_fee_correction as network_fee, -- the network fee
surplus + protocol_fee - reference_score as uncapped_payment,
observed_score - reference_score as uncapped_payment,
-- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth)
LEAST(
GREATEST(
- {{EPSILON_LOWER}},
surplus + protocol_fee - reference_score
observed_score - reference_score
),
{{EPSILON_UPPER}}
) as capped_payment,
Expand Down
9 changes: 7 additions & 2 deletions src/sql/orderbook/prod_batch_rewards.sql
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,11 @@ reward_data AS (
end as fee,
-- scores
winning_score,
case
when block_number is not null
and block_number <= block_deadline then winning_score
else 0
end as observed_score,
reference_score,
-- auction_participation
participating_solvers,
Expand Down Expand Up @@ -390,12 +395,12 @@ reward_per_auction as (
surplus,
protocol_fee, -- the protocol fee
fee - network_fee_correction as network_fee, -- the network fee
surplus + protocol_fee - reference_score as uncapped_payment,
observed_score - reference_score as uncapped_payment,
-- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth)
LEAST(
GREATEST(
- {{EPSILON_LOWER}},
surplus + protocol_fee - reference_score
observed_score - reference_score
),
{{EPSILON_UPPER}}
) as capped_payment,
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/test_fetch_orderbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,22 @@ def test_get_batch_rewards(self):
"8912931423922369",
],
"uncapped_payment_eth": [
"405658669881356",
"405658366132340",
"292618683544035",
"-13360904627424245",
"-12938581202699558",
"2823075137791897",
"9345865552057182",
"1607086130097916",
"1607086130097915",
],
"capped_payment": [
"405658669881356",
"405658366132340",
"292618683544035",
"-10000000000000000",
"-10000000000000000",
"2823075137791897",
"9345865552057182",
"1607086130097916",
"1607086130097915",
],
"winning_score": [
"11327955072945657",
Expand Down

0 comments on commit d3b054d

Please sign in to comment.