diff --git a/src/sql/orderbook/barn_batch_rewards.sql b/src/sql/orderbook/barn_batch_rewards.sql index b93cdae2..53664f3d 100644 --- a/src/sql/orderbook/barn_batch_rewards.sql +++ b/src/sql/orderbook/barn_batch_rewards.sql @@ -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, @@ -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, diff --git a/src/sql/orderbook/prod_batch_rewards.sql b/src/sql/orderbook/prod_batch_rewards.sql index b93cdae2..53664f3d 100644 --- a/src/sql/orderbook/prod_batch_rewards.sql +++ b/src/sql/orderbook/prod_batch_rewards.sql @@ -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, @@ -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, diff --git a/tests/integration/test_fetch_orderbook.py b/tests/integration/test_fetch_orderbook.py index 3acf8ec7..6475dd50 100644 --- a/tests/integration/test_fetch_orderbook.py +++ b/tests/integration/test_fetch_orderbook.py @@ -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",