diff --git a/queries/orderbook/batch_rewards.sql b/queries/orderbook/batch_rewards.sql index 1e997d69..2dcc7485 100644 --- a/queries/orderbook/batch_rewards.sql +++ b/queries/orderbook/batch_rewards.sql @@ -86,7 +86,7 @@ order_protocol_fee AS ( -- impossible anyways. This query will return a division by -- zero error in that case. LEAST( - fp.max_volume_factor * os.sell_amount * os.buy_amount / (os.sell_amount - os.observed_fee), + fp.max_volume_factor / (1 - fp.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 ) @@ -96,12 +96,14 @@ order_protocol_fee AS ( fp.surplus_factor / (1 - fp.surplus_factor) * surplus -- charge a fraction of surplus ) END - WHEN fp.kind = 'volume' THEN fp.volume_factor / (1 + fp.volume_factor) * os.sell_amount + 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, - CASE - WHEN fp.kind = 'surplus' THEN os.surplus_token - WHEN fp.kind = 'volume' THEN os.sell_token - END AS protocol_fee_token + os.surplus_token AS protocol_fee_token FROM order_surplus os JOIN fee_policies fp -- contains protocol fee policy @@ -268,4 +270,4 @@ select from aggregate_results order by - solver \ No newline at end of file + solver diff --git a/tests/queries/test_batch_rewards.py b/tests/queries/test_batch_rewards.py index e6e2db77..a55f01c3 100644 --- a/tests/queries/test_batch_rewards.py +++ b/tests/queries/test_batch_rewards.py @@ -29,7 +29,7 @@ def test_get_batch_rewards(self): "0x5444444444444444444444444444444444444444", ], "payment_eth": [ - 9.534313722772278e15, + 9535064849462312.0, 10.5e15, 6600000000000000.00000, 12450000000000000.00000, @@ -53,7 +53,7 @@ def test_get_batch_rewards(self): 6, ], "protocol_fee_eth": [ - 5.748876684972541e14, # 0.5 / (1 - 0.5) * 1e18 * 5e14 / 1e18 + 0.0015 / (1 + 0.0015) * 1e8 * 5e26 / 1e18 + 571357035553330.0, # 0.5 / (1 - 0.5) * 1e18 * 5e14 / 1e18 + 0.0015 / (1 - 0.0015) * 95e18 * 5e14 / 1e18 2.0198019801980198e15, # 0.75 / (1 - 0.75) * 1e6 * 5e26 / 1e18 + 0.01 / (1 + 0.01) * 105e6 * 5e26 / 1e18 0.0, 0.0,