diff --git a/queries/orderbook/barn_batch_rewards.sql b/queries/orderbook/barn_batch_rewards.sql index 7837853c..f9bc96b3 100644 --- a/queries/orderbook/barn_batch_rewards.sql +++ b/queries/orderbook/barn_batch_rewards.sql @@ -17,10 +17,10 @@ WITH observed_settlements AS ( ss.block_deadline >= {{start_block}} AND ss.block_deadline <= {{end_block}} ), -auction_participation as ( +auction_participation AS ( SELECT ss.auction_id, - array_agg(participant) as participating_solvers + array_agg(participant) AS participating_solvers FROM auction_participants JOIN settlement_scores ss ON auction_participants.auction_id = ss.auction_id @@ -52,10 +52,10 @@ order_data AS ( app_data FROM jit_orders ), --- additional trade data -order_surplus AS ( +-- unprocessed trade data +trade_data_unprocessed AS ( SELECT - ss.winner as solver, + ss.winner AS solver, s.auction_id, s.tx_hash, t.order_uid, @@ -63,21 +63,15 @@ order_surplus AS ( od.buy_token, t.sell_amount, -- the total amount the user sends t.buy_amount, -- the total amount the user receives - oe.surplus_fee as observed_fee, -- the total discrepancy between what the user sends and what they would have send if they traded at clearing price + oe.surplus_fee AS observed_fee, -- the total discrepancy between what the user sends and what they would have send if they traded at clearing price od.kind, - CASE - WHEN od.kind = 'sell' THEN t.buy_amount - t.sell_amount * od.buy_amount / od.sell_amount - WHEN od.kind = 'buy' THEN t.buy_amount * od.sell_amount / od.buy_amount - t.sell_amount - END AS surplus, - CASE - WHEN od.kind = 'sell' THEN t.buy_amount - t.sell_amount * (oq.buy_amount - oq.buy_amount / oq.sell_amount * oq.gas_amount * oq.gas_price / oq.sell_token_price) / oq.sell_amount - WHEN od.kind = 'buy' THEN t.buy_amount * (oq.sell_amount + oq.gas_amount * oq.gas_price / oq.sell_token_price) / oq.buy_amount - t.sell_amount - END AS price_improvement, CASE WHEN od.kind = 'sell' THEN od.buy_token WHEN od.kind = 'buy' THEN od.sell_token END AS surplus_token, - ad.full_app_data as app_data + convert_from(ad.full_app_data, 'UTF8')::JSONB->'metadata'->'partnerFee'->>'recipient' AS partner_fee_recipient, + COALESCE(oe.protocol_fee_amounts[1], 0) AS first_protocol_fee_amount, + COALESCE(oe.protocol_fee_amounts[2], 0) AS second_protocol_fee_amount FROM settlements s JOIN settlement_scores ss -- contains block_deadline @@ -89,282 +83,87 @@ order_surplus AS ( JOIN order_execution oe -- contains surplus fee ON t.order_uid = oe.order_uid AND s.auction_id = oe.auction_id - LEFT OUTER JOIN order_quotes oq -- contains quote amounts - ON od.uid = oq.order_uid LEFT OUTER JOIN app_data ad -- contains full app data - on od.app_data = ad.contract_app_data + ON od.app_data = ad.contract_app_data WHERE ss.block_deadline >= {{start_block}} AND ss.block_deadline <= {{end_block}} ), --- protocol fees: -fee_policies_first_proxy as ( - select - auction_id, - order_uid, - max(application_order) as application_order, - count (*) as num_policies - from fee_policies - where auction_id in (select auction_id from order_surplus) - group by order_uid, auction_id -), -fee_policies_first as ( - select - fp.auction_id, - fp.order_uid, - fp.application_order, - fp.kind, - fp.surplus_factor, - fp.surplus_max_volume_factor, - fp.volume_factor, - fp.price_improvement_factor, - fp.price_improvement_max_volume_factor - from fee_policies_first_proxy fpmp join fee_policies fp on fp.auction_id = fpmp.auction_id and fp.order_uid = fpmp.order_uid and fp.application_order = fpmp.application_order -), -fee_policies_temp as ( - select - * - from fee_policies - where auction_id in (select auction_id from order_surplus) - except (select * from fee_policies_first ) -), -fee_policies_second as ( - select - * - from fee_policies_temp - UNION - select - auction_id, - order_uid, - 0 as application_order, - 'volume' as kind, - null as surplus_factor, - null as surplus_max_volume_factor, - 0 as volume_factor, - null as price_improvement_factor, - null as price_improvement_max_volume_factor - from fee_policies_first_proxy where num_policies = 1 -), -order_protocol_fee_first AS ( +-- processed trade data: +trade_data_processed AS ( SELECT - os.auction_id, - os.order_uid, - os.sell_amount, - os.buy_amount, - os.surplus, - os.price_improvement, - os.kind, - convert_from(os.app_data, 'UTF8')::JSONB->'metadata'->'partnerFee'->>'recipient' as partner_fee_recipient, - fp.kind as protocol_fee_kind_first, - CASE - WHEN fp.kind = 'surplus' THEN CASE - WHEN os.kind = 'sell' THEN - -- We assume that the case surplus_factor != 1 always. In - -- that case reconstructing the protocol fee would be - -- impossible anyways. This query will return a division by - -- zero error in that case. - LEAST( - fp.surplus_max_volume_factor / (1 - fp.surplus_max_volume_factor) * os.buy_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * surplus -- charge a fraction of surplus - ) - WHEN os.kind = 'buy' THEN LEAST( - fp.surplus_max_volume_factor / (1 + fp.surplus_max_volume_factor) * os.sell_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * surplus -- charge a fraction of surplus - ) - END - WHEN fp.kind = 'priceimprovement' THEN CASE - WHEN os.kind = 'sell' THEN - LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 - fp.price_improvement_max_volume_factor) * os.buy_amount, - -- charge a fraction of price improvement, at most 0 - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * price_improvement - , - 0 - ) - ) - WHEN os.kind = 'buy' THEN LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 + fp.price_improvement_max_volume_factor) * os.sell_amount, - -- charge a fraction of price improvement - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * price_improvement, - 0 - ) - ) - END - WHEN fp.kind = 'volume' THEN CASE - WHEN os.kind = 'sell' THEN - fp.volume_factor / (1 - fp.volume_factor) * os.buy_amount - WHEN os.kind = 'buy' THEN - fp.volume_factor / (1 + fp.volume_factor) * os.sell_amount - END - END AS protocol_fee_first, - os.surplus_token AS protocol_fee_token - FROM - order_surplus os - JOIN fee_policies_first fp -- contains protocol fee policy - ON os.auction_id = fp.auction_id - AND os.order_uid = fp.order_uid -), -order_surplus_intermediate as ( - select auction_id, + solver, + tx_hash, order_uid, + sell_amount, + buy_amount, + sell_token, + observed_fee, + surplus_token, + second_protocol_fee_amount, + first_protocol_fee_amount + second_protocol_fee_amount AS protocol_fee, + partner_fee_recipient, CASE - WHEN kind = 'sell' then sell_amount - ELSE sell_amount - protocol_fee_first - END as sell_amount, - CASE - WHEN kind = 'sell' then buy_amount + protocol_fee_first - ELSE buy_amount - END as buy_amount, - surplus + protocol_fee_first as surplus, - price_improvement + protocol_fee_first as price_improvement, - protocol_fee_kind_first, - protocol_fee_first, - partner_fee_recipient - from order_protocol_fee_first -), -order_protocol_fee as materialized ( - SELECT - os.auction_id, - os.solver, - os.tx_hash, - os.order_uid, - os.sell_amount, - os.buy_amount, - os.sell_token, - os.observed_fee, - os.surplus, - os.surplus_token, - protocol_fee_kind_first, - fp.kind as protocol_fee_kind_second, - protocol_fee_first, - CASE - WHEN fp.kind = 'surplus' THEN CASE - WHEN os.kind = 'sell' THEN - -- We assume that the case surplus_factor != 1 always. In - -- that case reconstructing the protocol fee would be - -- impossible anyways. This query will return a division by - -- zero error in that case. - protocol_fee_first + LEAST( - fp.surplus_max_volume_factor / (1 - fp.surplus_max_volume_factor) * osi.buy_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * osi.surplus -- charge a fraction of surplus - ) - WHEN os.kind = 'buy' THEN protocol_fee_first + LEAST( - fp.surplus_max_volume_factor / (1 + fp.surplus_max_volume_factor) * osi.sell_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * osi.surplus -- charge a fraction of surplus - ) - END - WHEN fp.kind = 'priceimprovement' THEN CASE - WHEN os.kind = 'sell' THEN - protocol_fee_first + LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 - fp.price_improvement_max_volume_factor) * osi.buy_amount, - -- charge a fraction of price improvement, at most 0 - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * osi.price_improvement - , - 0 - ) - ) - WHEN os.kind = 'buy' THEN protocol_fee_first + LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 + fp.price_improvement_max_volume_factor) * osi.sell_amount, - -- charge a fraction of price improvement - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * osi.price_improvement, - 0 - ) - ) - END - WHEN fp.kind = 'volume' THEN CASE - WHEN os.kind = 'sell' THEN - protocol_fee_first + fp.volume_factor / (1 - fp.volume_factor) * osi.buy_amount - WHEN os.kind = 'buy' THEN - protocol_fee_first + fp.volume_factor / (1 + fp.volume_factor) * osi.sell_amount - END - END AS protocol_fee, - osi.partner_fee_recipient, - CASE - WHEN osi.partner_fee_recipient IS NOT NULL THEN osi.protocol_fee_first + WHEN partner_fee_recipient IS NOT NULL THEN second_protocol_fee_amount ELSE 0 END AS partner_fee, - os.surplus_token AS protocol_fee_token + surplus_token AS protocol_fee_token FROM - order_surplus os - JOIN order_surplus_intermediate osi - ON os.order_uid = osi.order_uid AND os.auction_id = osi.auction_id - JOIN fee_policies_second fp -- contains protocol fee policy - ON os.auction_id = fp.auction_id - AND os.order_uid = fp.order_uid + trade_data_unprocessed ), price_data AS ( SELECT - os.auction_id, - os.order_uid, - ap_surplus.price / pow(10, 18) as surplus_token_native_price, - ap_protocol.price / pow(10, 18) as protocol_fee_token_native_price, - ap_sell.price / pow(10, 18) as network_fee_token_native_price + tdp.auction_id, + tdp.order_uid, + ap_surplus.price / pow(10, 18) AS surplus_token_native_price, + ap_protocol.price / pow(10, 18) AS protocol_fee_token_native_price, + ap_sell.price / pow(10, 18) AS network_fee_token_native_price FROM - order_surplus AS os + trade_data_processed AS tdp LEFT OUTER JOIN auction_prices ap_sell -- contains price: sell token - ON os.auction_id = ap_sell.auction_id - AND os.sell_token = ap_sell.token + ON tdp.auction_id = ap_sell.auction_id + AND tdp.sell_token = ap_sell.token LEFT OUTER JOIN auction_prices ap_surplus -- contains price: surplus token - ON os.auction_id = ap_surplus.auction_id - AND os.surplus_token = ap_surplus.token + ON tdp.auction_id = ap_surplus.auction_id + AND tdp.surplus_token = ap_surplus.token LEFT OUTER JOIN auction_prices ap_protocol -- contains price: protocol fee token - ON os.auction_id = ap_protocol.auction_id - AND os.surplus_token = ap_protocol.token + ON tdp.auction_id = ap_protocol.auction_id + AND tdp.surplus_token = ap_protocol.token ), -combined_order_data AS ( +trade_data_processed_with_prices AS ( SELECT - os.auction_id, - os.solver, - os.tx_hash, - os.order_uid, - os.surplus, - os.surplus_token, - opf.protocol_fee, - opf.protocol_fee_token, + tdp.auction_id, + tdp.solver, + tdp.tx_hash, + tdp.order_uid, + tdp.surplus_token, + tdp.protocol_fee, + tdp.protocol_fee_token, + tdp.partner_fee, + tdp.partner_fee_recipient, CASE - WHEN opf.partner_fee_recipient IS NOT NULL THEN opf.protocol_fee_kind_second - ELSE opf.protocol_fee_kind_first - END AS protocol_fee_kind, - opf.partner_fee, - opf.partner_fee_recipient, - CASE - WHEN os.sell_token != os.surplus_token THEN os.observed_fee - (os.sell_amount - os.observed_fee) / os.buy_amount * coalesce(opf.protocol_fee, 0) - ELSE os.observed_fee - coalesce(opf.protocol_fee, 0) + WHEN tdp.sell_token != tdp.surplus_token THEN tdp.observed_fee - (tdp.sell_amount - tdp.observed_fee) / tdp.buy_amount * COALESCE(tdp.protocol_fee, 0) + ELSE tdp.observed_fee - COALESCE(tdp.protocol_fee, 0) END AS network_fee, - os.sell_token as network_fee_token, + tdp.sell_token AS network_fee_token, surplus_token_native_price, protocol_fee_token_native_price, network_fee_token_native_price FROM - order_surplus AS os - LEFT OUTER JOIN order_protocol_fee as opf - ON os.auction_id = opf.auction_id - AND os.order_uid = opf.order_uid + trade_data_processed AS tdp JOIN price_data pd - ON os.auction_id = pd.auction_id - AND os.order_uid = pd.order_uid + ON tdp.auction_id = pd.auction_id + AND tdp.order_uid = pd.order_uid ), batch_protocol_fees AS ( SELECT solver, tx_hash, - sum(protocol_fee * protocol_fee_token_native_price) as protocol_fee + sum(protocol_fee * protocol_fee_token_native_price) AS protocol_fee FROM - combined_order_data - group by + trade_data_processed_with_prices + GROUP BY solver, tx_hash ), @@ -372,10 +171,10 @@ batch_network_fees AS ( SELECT solver, tx_hash, - sum(network_fee * network_fee_token_native_price) as network_fee + sum(network_fee * network_fee_token_native_price) AS network_fee FROM - combined_order_data - group by + trade_data_processed_with_prices + GROUP BY solver, tx_hash ), @@ -386,27 +185,27 @@ reward_data AS ( ss.auction_id, -- TODO - Assuming that `solver == winner` when both not null -- We will need to monitor that `solver == winner`! - coalesce(os.solver, winner) as solver, - block_number as settlement_block, + COALESCE(os.solver, winner) AS solver, + block_number AS settlement_block, block_deadline, - coalesce(execution_cost, 0) as execution_cost, - coalesce(surplus, 0) as surplus, + COALESCE(execution_cost, 0) AS execution_cost, + COALESCE(surplus, 0) AS surplus, -- scores winning_score, - case - when block_number is not null - and block_number <= block_deadline + 1 then winning_score -- this includes a grace period of one block for settling a batch - else 0 - end as observed_score, + CASE + WHEN block_number IS NOT NULL + AND block_number <= block_deadline + 1 THEN winning_score -- this includes a grace period of one block for settling a batch + ELSE 0 + END AS observed_score, reference_score, -- auction_participation participating_solvers, -- protocol_fees - coalesce(cast(protocol_fee as numeric(78, 0)), 0) as protocol_fee, - coalesce( - cast(network_fee as numeric(78, 0)), + COALESCE(CAST(protocol_fee AS NUMERIC(78, 0)), 0) AS protocol_fee, + COALESCE( + CAST(network_fee AS NUMERIC(78, 0)), 0 - ) as network_fee + ) AS network_fee FROM settlement_scores ss -- If there are reported scores, @@ -417,7 +216,7 @@ reward_data AS ( LEFT OUTER JOIN batch_protocol_fees bpf ON bpf.tx_hash = os.tx_hash LEFT OUTER JOIN batch_network_fees bnf ON bnf.tx_hash = os.tx_hash ), -reward_per_auction as ( +reward_per_auction AS ( SELECT tx_hash, auction_id, @@ -428,7 +227,7 @@ reward_per_auction as ( surplus, protocol_fee, -- the protocol fee network_fee, -- the network fee - observed_score - reference_score as uncapped_payment, + observed_score - reference_score AS uncapped_payment, -- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth) LEAST( GREATEST( @@ -436,47 +235,47 @@ reward_per_auction as ( observed_score - reference_score ), {{EPSILON_UPPER}} - ) as capped_payment, + ) AS capped_payment, winning_score, reference_score, - participating_solvers as participating_solvers + participating_solvers AS participating_solvers FROM reward_data ), -participation_data as ( +participation_data AS ( SELECT tx_hash, block_deadline, - unnest(participating_solvers) as participant + unnest(participating_solvers) AS participant FROM reward_per_auction ), -participation_data_intermediate as ( +participation_data_intermediate AS ( SELECT tx_hash, CASE WHEN block_deadline <= 20365510 THEN 1 -- final block deadline of accounting week of July 16 - July 23, 2024 ELSE 0 - END as count_participation, + END AS count_participation, participant FROM participation_data ), -participation_counts as ( +participation_counts AS ( SELECT - participant as solver, - sum(count_participation) as num_participating_batches + participant AS solver, + sum(count_participation) AS num_participating_batches FROM participation_data_intermediate GROUP BY participant ), -primary_rewards as ( +primary_rewards AS ( SELECT rpt.solver, - SUM(capped_payment) as payment, - SUM(protocol_fee) as protocol_fee, - SUM(network_fee) as network_fee + SUM(capped_payment) AS payment, + SUM(protocol_fee) AS protocol_fee, + SUM(network_fee) AS network_fee FROM reward_per_auction rpt GROUP BY @@ -486,37 +285,37 @@ partner_fees_per_solver AS ( SELECT solver, partner_fee_recipient, - sum(partner_fee * protocol_fee_token_native_price) as partner_fee + sum(partner_fee * protocol_fee_token_native_price) AS partner_fee FROM - combined_order_data - WHERE partner_fee_recipient is not null - group by solver,partner_fee_recipient + trade_data_processed_with_prices + WHERE partner_fee_recipient IS NOT NULL + GROUP BY solver,partner_fee_recipient ), aggregate_partner_fees_per_solver AS ( SELECT solver, - array_agg(partner_fee_recipient) as partner_list, - array_agg(partner_fee) as partner_fee + array_agg(partner_fee_recipient) AS partner_list, + array_agg(partner_fee) AS partner_fee FROM partner_fees_per_solver - group by solver + GROUP BY solver ), -aggregate_results as ( +aggregate_results AS ( SELECT - concat('0x', encode(pc.solver, 'hex')) as solver, - coalesce(payment, 0) as primary_reward_eth, + CONCAT('0x', encode(pc.solver, 'hex')) AS solver, + COALESCE(payment, 0) AS primary_reward_eth, num_participating_batches, - coalesce(protocol_fee, 0) as protocol_fee_eth, - coalesce(network_fee, 0) as network_fee_eth, + COALESCE(protocol_fee, 0) AS protocol_fee_eth, + COALESCE(network_fee, 0) AS network_fee_eth, partner_list, - partner_fee as partner_fee_eth + partner_fee AS partner_fee_eth FROM participation_counts pc LEFT OUTER JOIN primary_rewards pr ON pr.solver = pc.solver - LEFT OUTER JOIN aggregate_partner_fees_per_solver aif on pr.solver = aif.solver + LEFT OUTER JOIN aggregate_partner_fees_per_solver aif ON pr.solver = aif.solver ) -- -select +SELECT * -from +FROM aggregate_results -order by +ORDER BY solver diff --git a/queries/orderbook/prod_batch_rewards.sql b/queries/orderbook/prod_batch_rewards.sql index 7837853c..f9bc96b3 100644 --- a/queries/orderbook/prod_batch_rewards.sql +++ b/queries/orderbook/prod_batch_rewards.sql @@ -17,10 +17,10 @@ WITH observed_settlements AS ( ss.block_deadline >= {{start_block}} AND ss.block_deadline <= {{end_block}} ), -auction_participation as ( +auction_participation AS ( SELECT ss.auction_id, - array_agg(participant) as participating_solvers + array_agg(participant) AS participating_solvers FROM auction_participants JOIN settlement_scores ss ON auction_participants.auction_id = ss.auction_id @@ -52,10 +52,10 @@ order_data AS ( app_data FROM jit_orders ), --- additional trade data -order_surplus AS ( +-- unprocessed trade data +trade_data_unprocessed AS ( SELECT - ss.winner as solver, + ss.winner AS solver, s.auction_id, s.tx_hash, t.order_uid, @@ -63,21 +63,15 @@ order_surplus AS ( od.buy_token, t.sell_amount, -- the total amount the user sends t.buy_amount, -- the total amount the user receives - oe.surplus_fee as observed_fee, -- the total discrepancy between what the user sends and what they would have send if they traded at clearing price + oe.surplus_fee AS observed_fee, -- the total discrepancy between what the user sends and what they would have send if they traded at clearing price od.kind, - CASE - WHEN od.kind = 'sell' THEN t.buy_amount - t.sell_amount * od.buy_amount / od.sell_amount - WHEN od.kind = 'buy' THEN t.buy_amount * od.sell_amount / od.buy_amount - t.sell_amount - END AS surplus, - CASE - WHEN od.kind = 'sell' THEN t.buy_amount - t.sell_amount * (oq.buy_amount - oq.buy_amount / oq.sell_amount * oq.gas_amount * oq.gas_price / oq.sell_token_price) / oq.sell_amount - WHEN od.kind = 'buy' THEN t.buy_amount * (oq.sell_amount + oq.gas_amount * oq.gas_price / oq.sell_token_price) / oq.buy_amount - t.sell_amount - END AS price_improvement, CASE WHEN od.kind = 'sell' THEN od.buy_token WHEN od.kind = 'buy' THEN od.sell_token END AS surplus_token, - ad.full_app_data as app_data + convert_from(ad.full_app_data, 'UTF8')::JSONB->'metadata'->'partnerFee'->>'recipient' AS partner_fee_recipient, + COALESCE(oe.protocol_fee_amounts[1], 0) AS first_protocol_fee_amount, + COALESCE(oe.protocol_fee_amounts[2], 0) AS second_protocol_fee_amount FROM settlements s JOIN settlement_scores ss -- contains block_deadline @@ -89,282 +83,87 @@ order_surplus AS ( JOIN order_execution oe -- contains surplus fee ON t.order_uid = oe.order_uid AND s.auction_id = oe.auction_id - LEFT OUTER JOIN order_quotes oq -- contains quote amounts - ON od.uid = oq.order_uid LEFT OUTER JOIN app_data ad -- contains full app data - on od.app_data = ad.contract_app_data + ON od.app_data = ad.contract_app_data WHERE ss.block_deadline >= {{start_block}} AND ss.block_deadline <= {{end_block}} ), --- protocol fees: -fee_policies_first_proxy as ( - select - auction_id, - order_uid, - max(application_order) as application_order, - count (*) as num_policies - from fee_policies - where auction_id in (select auction_id from order_surplus) - group by order_uid, auction_id -), -fee_policies_first as ( - select - fp.auction_id, - fp.order_uid, - fp.application_order, - fp.kind, - fp.surplus_factor, - fp.surplus_max_volume_factor, - fp.volume_factor, - fp.price_improvement_factor, - fp.price_improvement_max_volume_factor - from fee_policies_first_proxy fpmp join fee_policies fp on fp.auction_id = fpmp.auction_id and fp.order_uid = fpmp.order_uid and fp.application_order = fpmp.application_order -), -fee_policies_temp as ( - select - * - from fee_policies - where auction_id in (select auction_id from order_surplus) - except (select * from fee_policies_first ) -), -fee_policies_second as ( - select - * - from fee_policies_temp - UNION - select - auction_id, - order_uid, - 0 as application_order, - 'volume' as kind, - null as surplus_factor, - null as surplus_max_volume_factor, - 0 as volume_factor, - null as price_improvement_factor, - null as price_improvement_max_volume_factor - from fee_policies_first_proxy where num_policies = 1 -), -order_protocol_fee_first AS ( +-- processed trade data: +trade_data_processed AS ( SELECT - os.auction_id, - os.order_uid, - os.sell_amount, - os.buy_amount, - os.surplus, - os.price_improvement, - os.kind, - convert_from(os.app_data, 'UTF8')::JSONB->'metadata'->'partnerFee'->>'recipient' as partner_fee_recipient, - fp.kind as protocol_fee_kind_first, - CASE - WHEN fp.kind = 'surplus' THEN CASE - WHEN os.kind = 'sell' THEN - -- We assume that the case surplus_factor != 1 always. In - -- that case reconstructing the protocol fee would be - -- impossible anyways. This query will return a division by - -- zero error in that case. - LEAST( - fp.surplus_max_volume_factor / (1 - fp.surplus_max_volume_factor) * os.buy_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * surplus -- charge a fraction of surplus - ) - WHEN os.kind = 'buy' THEN LEAST( - fp.surplus_max_volume_factor / (1 + fp.surplus_max_volume_factor) * os.sell_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * surplus -- charge a fraction of surplus - ) - END - WHEN fp.kind = 'priceimprovement' THEN CASE - WHEN os.kind = 'sell' THEN - LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 - fp.price_improvement_max_volume_factor) * os.buy_amount, - -- charge a fraction of price improvement, at most 0 - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * price_improvement - , - 0 - ) - ) - WHEN os.kind = 'buy' THEN LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 + fp.price_improvement_max_volume_factor) * os.sell_amount, - -- charge a fraction of price improvement - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * price_improvement, - 0 - ) - ) - END - WHEN fp.kind = 'volume' THEN CASE - WHEN os.kind = 'sell' THEN - fp.volume_factor / (1 - fp.volume_factor) * os.buy_amount - WHEN os.kind = 'buy' THEN - fp.volume_factor / (1 + fp.volume_factor) * os.sell_amount - END - END AS protocol_fee_first, - os.surplus_token AS protocol_fee_token - FROM - order_surplus os - JOIN fee_policies_first fp -- contains protocol fee policy - ON os.auction_id = fp.auction_id - AND os.order_uid = fp.order_uid -), -order_surplus_intermediate as ( - select auction_id, + solver, + tx_hash, order_uid, + sell_amount, + buy_amount, + sell_token, + observed_fee, + surplus_token, + second_protocol_fee_amount, + first_protocol_fee_amount + second_protocol_fee_amount AS protocol_fee, + partner_fee_recipient, CASE - WHEN kind = 'sell' then sell_amount - ELSE sell_amount - protocol_fee_first - END as sell_amount, - CASE - WHEN kind = 'sell' then buy_amount + protocol_fee_first - ELSE buy_amount - END as buy_amount, - surplus + protocol_fee_first as surplus, - price_improvement + protocol_fee_first as price_improvement, - protocol_fee_kind_first, - protocol_fee_first, - partner_fee_recipient - from order_protocol_fee_first -), -order_protocol_fee as materialized ( - SELECT - os.auction_id, - os.solver, - os.tx_hash, - os.order_uid, - os.sell_amount, - os.buy_amount, - os.sell_token, - os.observed_fee, - os.surplus, - os.surplus_token, - protocol_fee_kind_first, - fp.kind as protocol_fee_kind_second, - protocol_fee_first, - CASE - WHEN fp.kind = 'surplus' THEN CASE - WHEN os.kind = 'sell' THEN - -- We assume that the case surplus_factor != 1 always. In - -- that case reconstructing the protocol fee would be - -- impossible anyways. This query will return a division by - -- zero error in that case. - protocol_fee_first + LEAST( - fp.surplus_max_volume_factor / (1 - fp.surplus_max_volume_factor) * osi.buy_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * osi.surplus -- charge a fraction of surplus - ) - WHEN os.kind = 'buy' THEN protocol_fee_first + LEAST( - fp.surplus_max_volume_factor / (1 + fp.surplus_max_volume_factor) * osi.sell_amount, - -- at most charge a fraction of volume - fp.surplus_factor / (1 - fp.surplus_factor) * osi.surplus -- charge a fraction of surplus - ) - END - WHEN fp.kind = 'priceimprovement' THEN CASE - WHEN os.kind = 'sell' THEN - protocol_fee_first + LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 - fp.price_improvement_max_volume_factor) * osi.buy_amount, - -- charge a fraction of price improvement, at most 0 - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * osi.price_improvement - , - 0 - ) - ) - WHEN os.kind = 'buy' THEN protocol_fee_first + LEAST( - -- at most charge a fraction of volume - fp.price_improvement_max_volume_factor / (1 + fp.price_improvement_max_volume_factor) * osi.sell_amount, - -- charge a fraction of price improvement - GREATEST( - fp.price_improvement_factor / (1 - fp.price_improvement_factor) * osi.price_improvement, - 0 - ) - ) - END - WHEN fp.kind = 'volume' THEN CASE - WHEN os.kind = 'sell' THEN - protocol_fee_first + fp.volume_factor / (1 - fp.volume_factor) * osi.buy_amount - WHEN os.kind = 'buy' THEN - protocol_fee_first + fp.volume_factor / (1 + fp.volume_factor) * osi.sell_amount - END - END AS protocol_fee, - osi.partner_fee_recipient, - CASE - WHEN osi.partner_fee_recipient IS NOT NULL THEN osi.protocol_fee_first + WHEN partner_fee_recipient IS NOT NULL THEN second_protocol_fee_amount ELSE 0 END AS partner_fee, - os.surplus_token AS protocol_fee_token + surplus_token AS protocol_fee_token FROM - order_surplus os - JOIN order_surplus_intermediate osi - ON os.order_uid = osi.order_uid AND os.auction_id = osi.auction_id - JOIN fee_policies_second fp -- contains protocol fee policy - ON os.auction_id = fp.auction_id - AND os.order_uid = fp.order_uid + trade_data_unprocessed ), price_data AS ( SELECT - os.auction_id, - os.order_uid, - ap_surplus.price / pow(10, 18) as surplus_token_native_price, - ap_protocol.price / pow(10, 18) as protocol_fee_token_native_price, - ap_sell.price / pow(10, 18) as network_fee_token_native_price + tdp.auction_id, + tdp.order_uid, + ap_surplus.price / pow(10, 18) AS surplus_token_native_price, + ap_protocol.price / pow(10, 18) AS protocol_fee_token_native_price, + ap_sell.price / pow(10, 18) AS network_fee_token_native_price FROM - order_surplus AS os + trade_data_processed AS tdp LEFT OUTER JOIN auction_prices ap_sell -- contains price: sell token - ON os.auction_id = ap_sell.auction_id - AND os.sell_token = ap_sell.token + ON tdp.auction_id = ap_sell.auction_id + AND tdp.sell_token = ap_sell.token LEFT OUTER JOIN auction_prices ap_surplus -- contains price: surplus token - ON os.auction_id = ap_surplus.auction_id - AND os.surplus_token = ap_surplus.token + ON tdp.auction_id = ap_surplus.auction_id + AND tdp.surplus_token = ap_surplus.token LEFT OUTER JOIN auction_prices ap_protocol -- contains price: protocol fee token - ON os.auction_id = ap_protocol.auction_id - AND os.surplus_token = ap_protocol.token + ON tdp.auction_id = ap_protocol.auction_id + AND tdp.surplus_token = ap_protocol.token ), -combined_order_data AS ( +trade_data_processed_with_prices AS ( SELECT - os.auction_id, - os.solver, - os.tx_hash, - os.order_uid, - os.surplus, - os.surplus_token, - opf.protocol_fee, - opf.protocol_fee_token, + tdp.auction_id, + tdp.solver, + tdp.tx_hash, + tdp.order_uid, + tdp.surplus_token, + tdp.protocol_fee, + tdp.protocol_fee_token, + tdp.partner_fee, + tdp.partner_fee_recipient, CASE - WHEN opf.partner_fee_recipient IS NOT NULL THEN opf.protocol_fee_kind_second - ELSE opf.protocol_fee_kind_first - END AS protocol_fee_kind, - opf.partner_fee, - opf.partner_fee_recipient, - CASE - WHEN os.sell_token != os.surplus_token THEN os.observed_fee - (os.sell_amount - os.observed_fee) / os.buy_amount * coalesce(opf.protocol_fee, 0) - ELSE os.observed_fee - coalesce(opf.protocol_fee, 0) + WHEN tdp.sell_token != tdp.surplus_token THEN tdp.observed_fee - (tdp.sell_amount - tdp.observed_fee) / tdp.buy_amount * COALESCE(tdp.protocol_fee, 0) + ELSE tdp.observed_fee - COALESCE(tdp.protocol_fee, 0) END AS network_fee, - os.sell_token as network_fee_token, + tdp.sell_token AS network_fee_token, surplus_token_native_price, protocol_fee_token_native_price, network_fee_token_native_price FROM - order_surplus AS os - LEFT OUTER JOIN order_protocol_fee as opf - ON os.auction_id = opf.auction_id - AND os.order_uid = opf.order_uid + trade_data_processed AS tdp JOIN price_data pd - ON os.auction_id = pd.auction_id - AND os.order_uid = pd.order_uid + ON tdp.auction_id = pd.auction_id + AND tdp.order_uid = pd.order_uid ), batch_protocol_fees AS ( SELECT solver, tx_hash, - sum(protocol_fee * protocol_fee_token_native_price) as protocol_fee + sum(protocol_fee * protocol_fee_token_native_price) AS protocol_fee FROM - combined_order_data - group by + trade_data_processed_with_prices + GROUP BY solver, tx_hash ), @@ -372,10 +171,10 @@ batch_network_fees AS ( SELECT solver, tx_hash, - sum(network_fee * network_fee_token_native_price) as network_fee + sum(network_fee * network_fee_token_native_price) AS network_fee FROM - combined_order_data - group by + trade_data_processed_with_prices + GROUP BY solver, tx_hash ), @@ -386,27 +185,27 @@ reward_data AS ( ss.auction_id, -- TODO - Assuming that `solver == winner` when both not null -- We will need to monitor that `solver == winner`! - coalesce(os.solver, winner) as solver, - block_number as settlement_block, + COALESCE(os.solver, winner) AS solver, + block_number AS settlement_block, block_deadline, - coalesce(execution_cost, 0) as execution_cost, - coalesce(surplus, 0) as surplus, + COALESCE(execution_cost, 0) AS execution_cost, + COALESCE(surplus, 0) AS surplus, -- scores winning_score, - case - when block_number is not null - and block_number <= block_deadline + 1 then winning_score -- this includes a grace period of one block for settling a batch - else 0 - end as observed_score, + CASE + WHEN block_number IS NOT NULL + AND block_number <= block_deadline + 1 THEN winning_score -- this includes a grace period of one block for settling a batch + ELSE 0 + END AS observed_score, reference_score, -- auction_participation participating_solvers, -- protocol_fees - coalesce(cast(protocol_fee as numeric(78, 0)), 0) as protocol_fee, - coalesce( - cast(network_fee as numeric(78, 0)), + COALESCE(CAST(protocol_fee AS NUMERIC(78, 0)), 0) AS protocol_fee, + COALESCE( + CAST(network_fee AS NUMERIC(78, 0)), 0 - ) as network_fee + ) AS network_fee FROM settlement_scores ss -- If there are reported scores, @@ -417,7 +216,7 @@ reward_data AS ( LEFT OUTER JOIN batch_protocol_fees bpf ON bpf.tx_hash = os.tx_hash LEFT OUTER JOIN batch_network_fees bnf ON bnf.tx_hash = os.tx_hash ), -reward_per_auction as ( +reward_per_auction AS ( SELECT tx_hash, auction_id, @@ -428,7 +227,7 @@ reward_per_auction as ( surplus, protocol_fee, -- the protocol fee network_fee, -- the network fee - observed_score - reference_score as uncapped_payment, + observed_score - reference_score AS uncapped_payment, -- Capped Reward = CLAMP_[-E, E + exec_cost](uncapped_reward_eth) LEAST( GREATEST( @@ -436,47 +235,47 @@ reward_per_auction as ( observed_score - reference_score ), {{EPSILON_UPPER}} - ) as capped_payment, + ) AS capped_payment, winning_score, reference_score, - participating_solvers as participating_solvers + participating_solvers AS participating_solvers FROM reward_data ), -participation_data as ( +participation_data AS ( SELECT tx_hash, block_deadline, - unnest(participating_solvers) as participant + unnest(participating_solvers) AS participant FROM reward_per_auction ), -participation_data_intermediate as ( +participation_data_intermediate AS ( SELECT tx_hash, CASE WHEN block_deadline <= 20365510 THEN 1 -- final block deadline of accounting week of July 16 - July 23, 2024 ELSE 0 - END as count_participation, + END AS count_participation, participant FROM participation_data ), -participation_counts as ( +participation_counts AS ( SELECT - participant as solver, - sum(count_participation) as num_participating_batches + participant AS solver, + sum(count_participation) AS num_participating_batches FROM participation_data_intermediate GROUP BY participant ), -primary_rewards as ( +primary_rewards AS ( SELECT rpt.solver, - SUM(capped_payment) as payment, - SUM(protocol_fee) as protocol_fee, - SUM(network_fee) as network_fee + SUM(capped_payment) AS payment, + SUM(protocol_fee) AS protocol_fee, + SUM(network_fee) AS network_fee FROM reward_per_auction rpt GROUP BY @@ -486,37 +285,37 @@ partner_fees_per_solver AS ( SELECT solver, partner_fee_recipient, - sum(partner_fee * protocol_fee_token_native_price) as partner_fee + sum(partner_fee * protocol_fee_token_native_price) AS partner_fee FROM - combined_order_data - WHERE partner_fee_recipient is not null - group by solver,partner_fee_recipient + trade_data_processed_with_prices + WHERE partner_fee_recipient IS NOT NULL + GROUP BY solver,partner_fee_recipient ), aggregate_partner_fees_per_solver AS ( SELECT solver, - array_agg(partner_fee_recipient) as partner_list, - array_agg(partner_fee) as partner_fee + array_agg(partner_fee_recipient) AS partner_list, + array_agg(partner_fee) AS partner_fee FROM partner_fees_per_solver - group by solver + GROUP BY solver ), -aggregate_results as ( +aggregate_results AS ( SELECT - concat('0x', encode(pc.solver, 'hex')) as solver, - coalesce(payment, 0) as primary_reward_eth, + CONCAT('0x', encode(pc.solver, 'hex')) AS solver, + COALESCE(payment, 0) AS primary_reward_eth, num_participating_batches, - coalesce(protocol_fee, 0) as protocol_fee_eth, - coalesce(network_fee, 0) as network_fee_eth, + COALESCE(protocol_fee, 0) AS protocol_fee_eth, + COALESCE(network_fee, 0) AS network_fee_eth, partner_list, - partner_fee as partner_fee_eth + partner_fee AS partner_fee_eth FROM participation_counts pc LEFT OUTER JOIN primary_rewards pr ON pr.solver = pc.solver - LEFT OUTER JOIN aggregate_partner_fees_per_solver aif on pr.solver = aif.solver + LEFT OUTER JOIN aggregate_partner_fees_per_solver aif ON pr.solver = aif.solver ) -- -select +SELECT * -from +FROM aggregate_results -order by +ORDER BY solver diff --git a/tests/queries/batch_rewards_test_db.sql b/tests/queries/batch_rewards_test_db.sql index f9074ed6..05e81ff3 100644 --- a/tests/queries/batch_rewards_test_db.sql +++ b/tests/queries/batch_rewards_test_db.sql @@ -10,8 +10,6 @@ DROP TYPE IF EXISTS OrderClass; DROP TABLE IF EXISTS order_quotes; DROP TABLE IF EXISTS trades; DROP TABLE IF EXISTS order_execution; -DROP TABLE IF EXISTS fee_policies; -DROP TYPE IF EXISTS PolicyKind; DROP TABLE IF EXISTS app_data; CREATE TABLE IF NOT EXISTS settlements @@ -126,31 +124,11 @@ CREATE TABLE IF NOT EXISTS order_execution auction_id bigint NOT NULL, reward double precision NOT NULL, surplus_fee numeric(78, 0) NOT NULL, - solver_fee numeric(78, 0), + protocol_fee_amounts numeric(78, 0)[], PRIMARY KEY (order_uid, auction_id) ); -CREATE TYPE PolicyKind AS ENUM ('surplus', 'volume', 'priceimprovement'); - -CREATE TABLE fee_policies ( - auction_id bigint NOT NULL, - order_uid bytea NOT NULL, - -- The order in which the fee policies are inserted and applied. - application_order SERIAL NOT NULL, - -- The type of the fee policy. - kind PolicyKind NOT NULL, - -- The fee should be taken as a percentage of the price improvement. The value is between 0 and 1. - surplus_factor double precision, - -- Cap the fee at a certain percentage of the order volume. The value is between 0 and 1. - surplus_max_volume_factor double precision, - -- The fee should be taken as a percentage of the order volume. The value is between 0 and 1. - volume_factor double precision, - price_improvement_factor double precision, - price_improvement_max_volume_factor double precision, - PRIMARY KEY (auction_id, order_uid, application_order) -); - CREATE TABLE app_data ( contract_app_data bytea PRIMARY KEY, full_app_data bytea NOT NULL @@ -166,7 +144,6 @@ TRUNCATE orders; TRUNCATE jit_orders; TRUNCATE order_quotes; TRUNCATE trades; -TRUNCATE fee_policies; TRUNCATE app_data; @@ -298,12 +275,6 @@ VALUES ('\x01'::bytea, '\x01'::bytea, '\x02'::bytea, 95000000, 94000000000000000 ('\x09'::bytea, '\x01'::bytea, '\x02'::bytea, 100000000, 94000000000000000000, 0, 'sell', 'f', 0, 'limit', '\x0000000000000000000000000000000000000000000000000000000000000000'::bytea), -- in market sell limit order ('\x0a'::bytea, '\x01'::bytea, '\x02'::bytea, 100000000, 94000000000000000000, 0, 'sell', 'f', 0, 'limit', '\x0000000000000000000000000000000000000000000000000000000000000000'::bytea); -- in market sell limit order -INSERT INTO order_quotes (order_uid, gas_amount, gas_price, sell_token_price, sell_amount, buy_amount, solver) -VALUES ('\x07'::bytea, 100000, 25000000000, 500000000., 100000000, 100000000000000000000, '\x01'::bytea), -('\x08'::bytea, 100000, 25000000000, 500000000., 100000000, 100000000000000000000, '\x02'::bytea), -('\x09'::bytea, 100000, 25000000000, 500000000., 100000000, 90000000000000000000, '\x02'::bytea), -('\x0a'::bytea, 100000, 25000000000, 500000000., 100000000, 100000000000000000000, '\x02'::bytea); - INSERT INTO trades (block_number, log_index, order_uid, sell_amount, buy_amount, fee_amount) VALUES (51, 0, '\x01'::bytea, 100000000, 95000000000000000000, 5000000), (52, 0, '\x02'::bytea, 105000000, 100000000000000000000, 5000000), @@ -316,25 +287,15 @@ VALUES (51, 0, '\x01'::bytea, 100000000, 95000000000000000000, 5000000), (59, 0, '\x09'::bytea, 100000000, 95000000000000000000, 0), (60, 0, '\x0a'::bytea, 100000000, 94500000000000000000, 0); -INSERT INTO order_execution (order_uid, auction_id, reward, surplus_fee, solver_fee) -VALUES ('\x03'::bytea, 53, 0, 6000000, NULL), -('\x04'::bytea, 54, 0, 6000000, NULL), -('\x05'::bytea, 55, 0, 6000000, NULL), -('\x06'::bytea, 56, 0, 6000000, NULL), -('\x07'::bytea, 57, 0, 6000000, NULL), -('\x08'::bytea, 58, 0, 6000000, NULL), -('\x09'::bytea, 59, 0, 6000000, NULL), -('\x0a'::bytea, 60, 0, 6000000, NULL); - -INSERT INTO fee_policies (auction_id, order_uid, application_order, kind, surplus_factor, surplus_max_volume_factor, volume_factor, price_improvement_factor, price_improvement_max_volume_factor) -VALUES (53, '\x03'::bytea, 3, 'surplus', 0.5, 0.02, NULL, NULL, NULL), -(54, '\x04'::bytea, 4, 'surplus', 0.75, 0.1, NULL, NULL, NULL), -(55, '\x05'::bytea, 5, 'volume', NULL, NULL, 0.0045, NULL, NULL), -(56, '\x06'::bytea, 6, 'surplus', 0.9, 0.01, NULL, NULL, NULL), -(57, '\x07'::bytea, 7, 'priceimprovement', NULL, NULL, NULL, 0.5, 0.01), -(58, '\x08'::bytea, 8, 'priceimprovement', NULL, NULL, NULL, 0.5, 0.01), -(59, '\x09'::bytea, 9, 'priceimprovement', NULL, NULL, NULL, 0.5, 0.01), -(60, '\x0a'::bytea, 9, 'priceimprovement', NULL, NULL, NULL, 0.5, 0.01); +INSERT INTO order_execution (order_uid, auction_id, reward, surplus_fee, protocol_fee_amounts) +VALUES ('\x03'::bytea, 53, 0, 6000000, ARRAY[1000000000000000000]), +('\x04'::bytea, 54, 0, 6000000, ARRAY[1000000]), +('\x05'::bytea, 55, 0, 6000000, ARRAY[1000000000000000000, 500000000000000000]), +('\x06'::bytea, 56, 0, 6000000, ARRAY[1000000]), +('\x07'::bytea, 57, 0, 6000000, ARRAY[1000000000000000000]), +('\x08'::bytea, 58, 0, 6000000, ARRAY[1000000]), +('\x09'::bytea, 59, 0, 6000000, ARRAY[1000000000000000000]), +('\x0a'::bytea, 60, 0, 6000000, ARRAY[1000000000000000000]); INSERT INTO app_data (contract_app_data, full_app_data) VALUES ('\x0000000000000000000000000000000000000000000000000000000000000000'::bytea, '\x7b7d'::bytea), diff --git a/tests/queries/test_batch_rewards.py b/tests/queries/test_batch_rewards.py index 3d3ce951..678ad84c 100644 --- a/tests/queries/test_batch_rewards.py +++ b/tests/queries/test_batch_rewards.py @@ -48,18 +48,18 @@ def test_get_batch_rewards(self): 6, ], "protocol_fee_eth": [ - 714716223003516.0, # 0.5 / (1 - 0.5) * 1e18 * 5e14 / 1e18 + 0.0045 / (1 - 0.0045) * 95e18 * 5e14 / 1e18 - 2.0198019801980198e15, # 0.75 / (1 - 0.75) * 1e6 * 5e26 / 1e18 + 0.01 / (1 + 0.01) * 105e6 * 5e26 / 1e18 - 1229797979797980.0, # 0.5 / (1 - 0.5) * 0.5e18 * 5e14 / 1e18 + 0.5 / (1 - 0.5) * 1e6 * 5e26 / 1e18 + 0.01 / (1 - 0.01) * 95e18 * 5e14 / 1e18 + 1250000000000000.0, # 0.5 / (1 - 0.5) * 1e18 * 5e14 / 1e18 + 0.0045 / (1 - 0.0045) * 95e18 * 5e14 / 1e18 + 1000000000000000.0, # 0.75 / (1 - 0.75) * 1e6 * 5e26 / 1e18 + 0.01 / (1 + 0.01) * 105e6 * 5e26 / 1e18 + 2000000000000000.0, # 0.5 / (1 - 0.5) * 0.5e18 * 5e14 / 1e18 + 0.5 / (1 - 0.5) * 1e6 * 5e26 / 1e18 + 0.01 / (1 - 0.01) * 95e18 * 5e14 / 1e18 0.0, 0.0, 0.0, 0.0, ], "network_fee_eth": [ - 5322197413111470.0, # around 2 * 6_000_000 * 5e26 / 1e18 - 714716223003516.0 - 3980198019801980.0, # around 2 * 6_000_000 * 5e26 / 1e18 - 2.0198019801980198e15 - 10779179226823200.0, # around 4 * 6_000_000 * 5e26 / 1e18 - 1229797979797980.0 + 4792548202188630.0, # around 2 * 6_000_000 * 5e26 / 1e18 - 1250000000000000.0 + 5000000000000000.0, # around 2 * 6_000_000 * 5e26 / 1e18 - 1000000000000000.0 + 10015762063681600.0, # around 4 * 6_000_000 * 5e26 / 1e18 - 2000000000000000.0 0.0, # zero due to missing surplus fee data 0.0, 0.0, @@ -75,7 +75,7 @@ def test_get_batch_rewards(self): None, ], "partner_fee_eth": [ - [214716223003516], + [250000000000000.0], None, None, None,