Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit d3b054d

Browse files
authored
Merge pull request #104 from cowprotocol/reward_from_scores
[Mirror] Use scores instead of surplus for reward computation
2 parents b778238 + 612bf72 commit d3b054d

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/sql/orderbook/barn_batch_rewards.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ reward_data AS (
361361
end as fee,
362362
-- scores
363363
winning_score,
364+
case
365+
when block_number is not null
366+
and block_number <= block_deadline then winning_score
367+
else 0
368+
end as observed_score,
364369
reference_score,
365370
-- auction_participation
366371
participating_solvers,
@@ -390,12 +395,12 @@ reward_per_auction as (
390395
surplus,
391396
protocol_fee, -- the protocol fee
392397
fee - network_fee_correction as network_fee, -- the network fee
393-
surplus + protocol_fee - reference_score as uncapped_payment,
398+
observed_score - reference_score as uncapped_payment,
394399
-- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth)
395400
LEAST(
396401
GREATEST(
397402
- {{EPSILON_LOWER}},
398-
surplus + protocol_fee - reference_score
403+
observed_score - reference_score
399404
),
400405
{{EPSILON_UPPER}}
401406
) as capped_payment,

src/sql/orderbook/prod_batch_rewards.sql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ reward_data AS (
361361
end as fee,
362362
-- scores
363363
winning_score,
364+
case
365+
when block_number is not null
366+
and block_number <= block_deadline then winning_score
367+
else 0
368+
end as observed_score,
364369
reference_score,
365370
-- auction_participation
366371
participating_solvers,
@@ -390,12 +395,12 @@ reward_per_auction as (
390395
surplus,
391396
protocol_fee, -- the protocol fee
392397
fee - network_fee_correction as network_fee, -- the network fee
393-
surplus + protocol_fee - reference_score as uncapped_payment,
398+
observed_score - reference_score as uncapped_payment,
394399
-- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth)
395400
LEAST(
396401
GREATEST(
397402
- {{EPSILON_LOWER}},
398-
surplus + protocol_fee - reference_score
403+
observed_score - reference_score
399404
),
400405
{{EPSILON_UPPER}}
401406
) as capped_payment,

tests/integration/test_fetch_orderbook.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,22 @@ def test_get_batch_rewards(self):
252252
"8912931423922369",
253253
],
254254
"uncapped_payment_eth": [
255-
"405658669881356",
255+
"405658366132340",
256256
"292618683544035",
257257
"-13360904627424245",
258258
"-12938581202699558",
259259
"2823075137791897",
260260
"9345865552057182",
261-
"1607086130097916",
261+
"1607086130097915",
262262
],
263263
"capped_payment": [
264-
"405658669881356",
264+
"405658366132340",
265265
"292618683544035",
266266
"-10000000000000000",
267267
"-10000000000000000",
268268
"2823075137791897",
269269
"9345865552057182",
270-
"1607086130097916",
270+
"1607086130097915",
271271
],
272272
"winning_score": [
273273
"11327955072945657",

0 commit comments

Comments
 (0)