From beb8b1da4c416f3880c3ee26a3505d36c677893c Mon Sep 17 00:00:00 2001 From: Benjamin Smith Date: Mon, 19 Dec 2022 17:03:01 +0100 Subject: [PATCH] [V2] Deduct Surplus Fee in Slippage (#160) --- queries/dune_v2/period_slippage.sql | 25 +++++++++++------------ src/queries.py | 2 +- tests/integration/test_solver_slippage.py | 8 +++++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/queries/dune_v2/period_slippage.sql b/queries/dune_v2/period_slippage.sql index fd19f69f..613a0105 100644 --- a/queries/dune_v2/period_slippage.sql +++ b/queries/dune_v2/period_slippage.sql @@ -1,3 +1,4 @@ +-- Query here: https://dune.com/queries/1777559 with filtered_trades as ( select t.block_time, @@ -7,27 +8,25 @@ filtered_trades as ( -- Estimation made here: https://dune.com/queries/1646084 then ((gas_used - 73688 - (70528 * num_trades)) / 90000)::int else dex_swaps - end as dex_swaps, + end as dex_swaps, num_trades, - solver_address, - trader as trader_in, - -- Null Receiver: https://dune.com/queries/1729130 - -- TODO - This could also be fixed in the spellbook! - case - when receiver = '0x0000000000000000000000000000000000000000' - then trader - else receiver end as trader_out, - sell_token_address as sell_token, - buy_token_address as buy_token, - atoms_sold, + b.solver_address, + trader as trader_in, + receiver as trader_out, + sell_token_address as sell_token, + buy_token_address as buy_token, + atoms_sold - coalesce(surplus_fee, 0) as atoms_sold, atoms_bought, '0x9008d19f58aabd9ed0d60971565aa8510560ab41' as contract_address from cow_protocol_ethereum.trades t join cow_protocol_ethereum.batches b on t.tx_hash = b.tx_hash + left outer join cow_protocol_ethereum.order_rewards f + on f.tx_hash = t.tx_hash + and f.order_uid = t.order_uid where b.block_time between '{{StartTime}}' and '{{EndTime}}' and t.block_time between '{{StartTime}}' and '{{EndTime}}' - and (solver_address = lower('{{SolverAddress}}') or '{{SolverAddress}}' = '0x') + and (b.solver_address = lower('{{SolverAddress}}') or '{{SolverAddress}}' = '0x') and (t.tx_hash = lower('{{TxHash}}') or '{{TxHash}}' = '0x') ), batchwise_traders as ( diff --git a/src/queries.py b/src/queries.py index d8503cee..3a118bca 100644 --- a/src/queries.py +++ b/src/queries.py @@ -96,6 +96,6 @@ def with_params( name="Solver Slippage for Period", filepath="period_slippage.sql", v1_id=1728478, - v2_id=1729274, + v2_id=1777559, ), } diff --git a/tests/integration/test_solver_slippage.py b/tests/integration/test_solver_slippage.py index 760ed73b..841a39d4 100644 --- a/tests/integration/test_solver_slippage.py +++ b/tests/integration/test_solver_slippage.py @@ -246,8 +246,8 @@ def test_limit_order_slippage(self): table_name, period=AccountingPeriod("2022-11-29", 1), tx_hash="0xfe4589525c1ed764273fbca9120b0e5f7f101d5d4996939ead95a50312f4d8b3", - v1_cache="01GKS1X2Y18ECYRRJPCSGEE57X", - v2_cache="01GKS1X8BPMXMD9FQ4T1ER22YW", + v1_cache="01GMMZWQC8MGGHSPQP2RY9G00G", + v2_cache="01GMMZWWW0E28Q78S2K29NMHK0", ) known_surplus_fee = 1323758338760117 @@ -276,7 +276,9 @@ def test_limit_order_slippage(self): delta=13, ) # V2 Query does not yet implement surplus fee. - self.assertAlmostEqual(weth_in, parsed_v2["WETH"], places=18) + self.assertAlmostEqual( + weth_in - known_surplus_fee, parsed_v2["WETH"], places=18 + ) if __name__ == "__main__":