From 3648728e2505557895f9de1871d5c8a5accc2e04 Mon Sep 17 00:00:00 2001 From: Matias <76445289+matsai5@users.noreply.github.com> Date: Fri, 26 Dec 2025 19:42:30 +0100 Subject: [PATCH 1/5] added block_time to cow markout query --- .../execution_quality/markout/cow_markout_6031665.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cowprotocol/execution_quality/markout/cow_markout_6031665.sql b/cowprotocol/execution_quality/markout/cow_markout_6031665.sql index 76bf010a..e7902a54 100644 --- a/cowprotocol/execution_quality/markout/cow_markout_6031665.sql +++ b/cowprotocol/execution_quality/markout/cow_markout_6031665.sql @@ -8,11 +8,14 @@ -- {{max_usd_amount}} - Maximum USD amount of the trade to be considered select + block_time, tx_hash, token_bought_amount, token_sold_amount, token_bought_address, token_sold_address, + token_bought_symbol, + token_sold_symbol, sell.price as sellprice, buy.price as buyprice, amount_usd, @@ -33,7 +36,5 @@ where and token_pair is not null and block_date >= timestamp '{{start_date}}' and block_date < timestamp '{{end_date}}' - and token_bought_amount * buy.price >= {{min_usd_amount}} - and token_bought_amount * buy.price <= {{max_usd_amount}} - and token_sold_amount * sell.price >= {{min_usd_amount}} - and token_sold_amount * sell.price <= {{max_usd_amount}} + and token_bought_amount * buy.price between {{min_usd_amount}} and {{max_usd_amount}} + and token_sold_amount * sell.price between {{min_usd_amount}} and {{max_usd_amount}} From c9c88e43714c40a2909fc05f3651f2e3c4adc4c0 Mon Sep 17 00:00:00 2001 From: Matias <76445289+matsai5@users.noreply.github.com> Date: Fri, 26 Dec 2025 19:44:24 +0100 Subject: [PATCH 2/5] added block times to 1inch intent based markout --- .../markout/oneich_fusion_markout_6031733.sql | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cowprotocol/execution_quality/markout/oneich_fusion_markout_6031733.sql b/cowprotocol/execution_quality/markout/oneich_fusion_markout_6031733.sql index d90442b9..7e7efc48 100644 --- a/cowprotocol/execution_quality/markout/oneich_fusion_markout_6031733.sql +++ b/cowprotocol/execution_quality/markout/oneich_fusion_markout_6031733.sql @@ -1,4 +1,4 @@ --- 1inch fusion markout calculation. Compares the price of prices.usd table at the time of the trade to the executed amounts +-- 1inch intent based modes markout calculation. Compares the price of prices.usd table at the time of the trade to the executed amounts -- Parameters: -- {{blockchain}} - The chain on which trades should be counted @@ -8,30 +8,30 @@ -- {{max_usd_amount}} - Maximum USD amount of the trade to be considered select + block_time, tx_hash, - dst_token_amount, - src_token_amount, + cast(dst_executed_amount as double) /pow(10, cast(complement['dst_decimals'] as bigint)) as dst_exec_amount, + cast(src_executed_amount as double) /pow(10, cast(complement['src_decimals'] as bigint)) as src_exec_amount, dst_token_address, src_token_address, sell.price as sellprice, buy.price as buyprice, amount_usd, - ((dst_token_amount/pow(10,dst_token_decimals))/(src_token_amount/pow(10,src_token_decimals)) / (sell.price / buy.price)) - 1.0000 as markout + (cast(dst_executed_amount as double) /pow(10, cast(complement['dst_decimals'] as bigint))) / (cast(src_executed_amount as double)/pow(10, cast(complement['src_decimals'] as bigint))) / (sell.price / buy.price) - 1.0000 as markout from oneinch.swaps as t join prices.usd as sell on sell.contract_address = src_token_address and sell.minute = date_trunc('minute', block_time) and sell.price > 0 - and sell.blockchain = t.blockchain + and sell.blockchain = '{{blockchain}}' join prices.usd as buy on buy.contract_address = dst_token_address and buy.minute = date_trunc('minute', block_time) and buy.price > 0 - and buy.blockchain = t.blockchain + and buy.blockchain = '{{blockchain}}' where t.blockchain = '{{blockchain}}' and block_time >= timestamp '{{start_date}}' and block_time < timestamp '{{end_date}}' - and amount_usd <= {{max_usd_amount}} - and amount_usd >= {{min_usd_amount}} - and flags['fusion'] + and amount_usd between {{min_usd_amount}} and {{max_usd_amount}} + and mode in ('fusion', 'cross_chain') From 101a4482600517a0d3324d465793684bc1ad891a Mon Sep 17 00:00:00 2001 From: Matias <76445289+matsai5@users.noreply.github.com> Date: Fri, 26 Dec 2025 19:45:18 +0100 Subject: [PATCH 3/5] added block time for non-intent aggregator markout --- .../non_intent_aggregator_markout_6031688.sql | 92 +++++++++++-------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/cowprotocol/execution_quality/markout/non_intent_aggregator_markout_6031688.sql b/cowprotocol/execution_quality/markout/non_intent_aggregator_markout_6031688.sql index 4bae4f99..7652b723 100644 --- a/cowprotocol/execution_quality/markout/non_intent_aggregator_markout_6031688.sql +++ b/cowprotocol/execution_quality/markout/non_intent_aggregator_markout_6031688.sql @@ -1,17 +1,19 @@ ---- Markout calculation for non-intent DEX aggregator trades. Compares the price of dex.prices table at the time of the trade to the executed amounts and factors in gas costs. ---- Returns a per transaction hash buy and sell USD value, gas cost in USD and the resulting markout. +-- Markout calculation for non-intent DEX aggregator trades. +-- Compares the price of prices.usd table at the time of the trade to the executed amounts and factors in gas costs. +-- Returns buy and sell USD value, gas cost in USD and the resulting markout, all per tx hash. -- Parameters: --- {{project}} - The aggregator to look at --- {{start_date}} - Start date for when trades should be counted --- {{end_date}} - End date for when trades should be counted +-- {{project}} - The aggregator to consider +-- {{start_date}} - Start date for when trades should be counted, inclusive +-- {{end_date}} - End date for when trades should be counted, exclusive -- {{blockchain}} - The chain on which trades should be counted --- {{native_token}} - The native token of the blockchain (e.g. ETH for Ethereum) -- {{min_usd_amount}} - Minimum USD amount of the trade to be considered -- {{max_usd_amount}} - Maximum USD amount of the trade to be considered -with markout_per_trade as ( - select +with +markout_per_trade as ( + select + block_time, tx_hash, token_bought_amount, token_sold_amount, @@ -35,38 +37,56 @@ with markout_per_trade as ( and buy.blockchain = t.blockchain where t.blockchain = '{{blockchain}}' - and project = '{{project}}' + and if(project='0x API', '0x', project) = '{{project}}' -- this fixes a weird parameter bug and t.block_time >= timestamp '{{start_date}}' and t.block_time < timestamp '{{end_date}}' - and amount_usd >= {{min_usd_amount}} - and amount_usd <= {{max_usd_amount}} + and amount_usd between {{min_usd_amount}} and {{max_usd_amount}} ), - -markout_by_tx as ( - select - tx_hash, +-- remove 1inch intent based txs +oneinch_intent_based as ( + select distinct tx_hash + from oneinch.swaps + where + mode in ('fusion', 'cross-chain') + and block_time >= timestamp '{{start_date}}' + and block_time < timestamp '{{end_date}}' +), +agg_by_tx as ( + select + a.block_time, + a.tx_hash, sum(buy_usd_value) as buy_usd_value, sum(sell_usd_value) as sell_usd_value - from markout_per_trade - group by 1 + from markout_per_trade as a + left join oneinch_intent_based as b + on a.tx_hash = b.tx_hash + where b.tx_hash is null + group by 1,2 +) +, native_prices as ( + select + minute, + price + from prices.usd + where + contract_address = (select price_address from tokens.native where chain = '{{blockchain}}') + and blockchain = '{{blockchain}}' + and minute >= timestamp '{{start_date}}' + and minute < timestamp '{{end_date}}' ) - select - tx_hash, - buy_usd_value, - sell_usd_value, - (gas_used * gas_price * eth.price) / 1e18 as gas_usd, - (buy_usd_value/(sell_usd_value + (gas_used * gas_price * eth.price) / 1e18 )) - 1.0000 as markout -from markout_by_tx -join {{blockchain}}.transactions - on tx_hash = hash -join prices.usd as eth - on eth.contract_address = {{native_token}} - and eth.minute = date_trunc('minute', block_time) - and eth.blockchain = '{{blockchain}}' - -- filter out extreme native prices - and buy_usd_value >= {{min_usd_amount}} - and buy_usd_value <= {{max_usd_amount}} - and sell_usd_value >= {{min_usd_amount}} - and sell_usd_value <= {{max_usd_amount}} -order by markout asc + aggtx.block_time, + aggtx.tx_hash, + aggtx.buy_usd_value, + aggtx.sell_usd_value, + (tx.gas_used * tx.gas_price * np.price) / 1e18 as gas_usd, + (aggtx.buy_usd_value/(aggtx.sell_usd_value + (tx.gas_used * tx.gas_price * np.price) / 1e18 )) - 1.0000 as markout +from agg_by_tx as aggtx +join {{blockchain}}.transactions as tx + on aggtx.tx_hash = tx.hash +join native_prices as np + on np.minute = date_trunc('minute', tx.block_time) +where + aggtx.buy_usd_value between {{min_usd_amount}} and {{max_usd_amount}} + and aggtx.sell_usd_value between {{min_usd_amount}} and {{max_usd_amount}} +order by markout From 33f131813fc00d93662bc452d884b62cac319d93 Mon Sep 17 00:00:00 2001 From: Matias <76445289+matsai5@users.noreply.github.com> Date: Fri, 26 Dec 2025 19:46:45 +0100 Subject: [PATCH 4/5] add block time to uniswap x markouts --- .../markout/uniswapx_markout_6033942.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cowprotocol/execution_quality/markout/uniswapx_markout_6033942.sql b/cowprotocol/execution_quality/markout/uniswapx_markout_6033942.sql index a6b079dc..8fa79c7c 100644 --- a/cowprotocol/execution_quality/markout/uniswapx_markout_6033942.sql +++ b/cowprotocol/execution_quality/markout/uniswapx_markout_6033942.sql @@ -8,11 +8,14 @@ -- {{max_usd_amount}} - Maximum USD amount of the trade to be considered select + block_time, tx_hash, token_bought_amount, token_sold_amount, token_bought_address, token_sold_address, + sell_token, + buy_token, sell_price as sellprice, buy_price as buyprice, amount_usd, @@ -22,7 +25,5 @@ where blockchain = '{{blockchain}}' and block_time >= timestamp '{{start_date}}' and block_time < timestamp '{{end_date}}' - and token_bought_amount * buy_price >= {{min_usd_amount}} - and token_bought_amount * buy_price <= {{max_usd_amount}} - and token_sold_amount * sell_price >= {{min_usd_amount}} - and token_sold_amount * sell_price <= {{max_usd_amount}} + and token_bought_amount * buy_price between {{min_usd_amount}} and {{max_usd_amount}} + and token_sold_amount * sell_price between {{min_usd_amount}} and {{max_usd_amount}} From 7d58c61fe1e6897ee3ba8f70bce86c6bf05d7792 Mon Sep 17 00:00:00 2001 From: Matias <76445289+matsai5@users.noreply.github.com> Date: Fri, 26 Dec 2025 19:49:42 +0100 Subject: [PATCH 5/5] Add markouts over time query --- .../markout/markouts_over_time_6423541.sql | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 cowprotocol/execution_quality/markout/markouts_over_time_6423541.sql diff --git a/cowprotocol/execution_quality/markout/markouts_over_time_6423541.sql b/cowprotocol/execution_quality/markout/markouts_over_time_6423541.sql new file mode 100644 index 00000000..6826b909 --- /dev/null +++ b/cowprotocol/execution_quality/markout/markouts_over_time_6423541.sql @@ -0,0 +1,89 @@ +-- Markout comparison across multiple DEX aggregators and CoW Protocol over time +-- Returns markout avg and percentiles in basis points (bps) for each project over the specified time period + +-- Parameters: +-- {{blockchain}} - The chain on which trades should be counted +-- {{start_date}} - Start date for when trades should be counted +-- {{end_date}} - End date for when trades should be counted +-- {{min_usd_amount}} - Minimum USD amount of the trade to be considered +-- {{max_usd_amount}} - Maximum USD amount of the trade to be considered + +select + 'CoW' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031665(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}')" +group by 1 , 2 +union all +select + '1inch (intent based)' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031733(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}')" +group by 1 , 2 +union all +select + 'Uniswap X' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6033942(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}')" +group by 1 , 2 +union all +select + '1inch (non intent based)' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031688(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}',project='1inch')" +group by 1 , 2 +union all +select + 'Kyberswap' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031688(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}',project='kyberswap')" +group by 1 , 2 +union all +select + 'Paraswap' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031688(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}',project='paraswap')" +group by 1 , 2 +union all +select + 'Odos' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031688(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}',project='odos')" +group by 1 , 2 +union all +select + '0x' as project + , date_trunc('{{date_granularity}}', block_time) as date + , avg(markout) * 10000 as avg_markout_bps + , approx_percentile(markout, 0.25) * 10000 as p25_markout_bps + , approx_percentile(markout, 0.50) * 10000 as p50_markout_bps + , approx_percentile(markout, 0.75) * 10000 as p75_markout_bps +from "query_6031688(blockchain='{{blockchain}}',start_date='{{start_date}}',end_date='{{end_date}}',min_usd_amount='{{min_usd_amount}}',max_usd_amount='{{max_usd_amount}}',project='0x')" +group by 1 , 2