diff --git a/cowprotocol/competitor_analysis/.sqlfluff b/cowprotocol/competitor_analysis/.sqlfluff new file mode 100644 index 0000000..8f9dbcc --- /dev/null +++ b/cowprotocol/competitor_analysis/.sqlfluff @@ -0,0 +1,5 @@ +[sqlfluff:templater:jinja:context] +start_time='2024-08-01 12:00' +end_time='2024-08-02 12:00' +chain_of_interest='ethereum' +show_competitors_on_target_chain_only=1 \ No newline at end of file diff --git a/cowprotocol/competitor_analysis/cow_alternatives_analysis_4810844.sql b/cowprotocol/competitor_analysis/cow_alternatives_analysis_4810844.sql new file mode 100644 index 0000000..d4012c4 --- /dev/null +++ b/cowprotocol/competitor_analysis/cow_alternatives_analysis_4810844.sql @@ -0,0 +1,95 @@ +-- Get all users who are using COW Protocol on any chain but {{chain_of_interest}} +-- Get aggregates (tx_count, usd_volume, user_count) of other dexes/aggregators they use on all chains supported by cow +-- or limit the results to only competitor usage on {{chain_of_interest}} if {{show_competitors_on_target_chain_only}} is set to 1 +-- +-- Parameters: +-- {{start_time}} - the trade timestamp for which the analysis should start (inclusive) +-- {{end_time}} - the trade timestamp for which the analysis should end (inclusive) +-- {{chain_of_interest}} - which chain is not used by cohort of users we want to investigate +-- {{show_competitors_on_target_chain_only}} - filters competitor's usage to only {{chain_of_interest}} + +with all_cow_users as ( + select + tx_from as address, + array_agg(distinct blockchain) as uses_on_chains + from + dex_aggregator.trades + where + project = 'cow_protocol' + and + block_time between timestamp '{{start_time}}' and timestamp '{{end_time}}' + group by + 1 +), + +cow_users_filtered as ( + select * + from + all_cow_users + where + not contains(uses_on_chains, '{{chain_of_interest}}') +), + +chains_supported_by_cow as ( + select distinct blockchain + from + dex_aggregator.trades + where + project = 'cow_protocol' +), + +trades_dex_and_aggregators as ( + select + tx_from, + blockchain, + project, + amount_usd + from + dex.trades + where + blockchain in (select blockchain from chains_supported_by_cow) + and + block_time between timestamp '{{start_time}}' and timestamp '{{end_time}}' + + union all + + select + tx_from, + blockchain, + project, + amount_usd + from + dex_aggregator.trades + where + project != 'cow_protocol' + and + blockchain in (select blockchain from chains_supported_by_cow) + and + block_time between timestamp '{{start_time}}' and timestamp '{{end_time}}' +), + +all_competitor_transactions as ( + select + tx_from as address, + blockchain as chain_used_for_competitor, + project as competitor_project, + sum(amount_usd) as competitor_total_volume_usd, + count(*) as competitor_total_transactions + from + trades_dex_and_aggregators + group by 1, 2, 3 +) + +select + chain_used_for_competitor, + competitor_project, + sum(competitor_total_volume_usd) as competitor_total_volume_usd, + sum(competitor_total_transactions) as competitor_total_transactions, + count(distinct address) as distinct_users_count +from + cow_users_filtered +left join all_competitor_transactions using (address) -- noqa: disable=L032 +where + {{show_competitors_on_target_chain_only}} = 0 or chain_used_for_competitor = '{{chain_of_interest}}' +group by 1, 2 +order by 3 desc diff --git a/cowprotocol/competitor_analysis/cow_vs_competition_4807448.sql b/cowprotocol/competitor_analysis/cow_vs_competition_4807448.sql new file mode 100644 index 0000000..6374e8d --- /dev/null +++ b/cowprotocol/competitor_analysis/cow_vs_competition_4807448.sql @@ -0,0 +1,112 @@ +-- Get all users who are using COW Protocol on any chain. +-- Get aggregates (tx_count, usd_volume, user_count) of other [dexes/aggregators, chain] pairs that are used by our users. +-- Join competitor usage and cow protocol usage on the same chain (using user address). +-- Form a cohorts that will be compared using the aggregates (tx_count, usd_volume, user_count) . +-- +-- Parameters: +-- {{start_time}} - the trade timestamp for which the analysis should start (inclusive) +-- {{end_time}} - the trade timestamp for which the analysis should end (inclusive) + +with cow_protocol_target_users as ( + select + tx_from as address, + blockchain as chain_used_for_cow, + count(*) as total_transactions_on_cow, + sum(amount_usd) as total_volume_usd_on_cow + from + dex_aggregator.trades + where + project = 'cow_protocol' + and + block_time between timestamp '{{start_time}}' and timestamp '{{end_time}}' + group by + 1, 2 +), + +users_per_chain_cow as ( + select + chain_used_for_cow, + count(distinct address) as distinct_users_cow + from + cow_protocol_target_users + group by + 1 +), + +chains_supported_by_cow as ( + select distinct chain_used_for_cow as blockchain + from + cow_protocol_target_users +), + +trades_dex_and_aggregators as ( + select + tx_from, + blockchain, + project, + amount_usd + from + dex.trades + where + blockchain in (select blockchain from chains_supported_by_cow) + and + block_time between timestamp '{{start_time}}' and timestamp '{{end_time}}' + + union all + + select + tx_from, + blockchain, + project, + amount_usd + from + dex_aggregator.trades + where + project != 'cow_protocol' + and + blockchain in (select blockchain from chains_supported_by_cow) + and + block_time between timestamp '{{start_time}}' and timestamp '{{end_time}}' +), + +all_competitor_transactions as ( + select + tx_from as address, + blockchain as chain_used_for_competitor, + project as competitor_project, + sum(amount_usd) as competitor_total_volume_usd, + count(*) as competitor_total_transactions + from + trades_dex_and_aggregators + group by 1, 2, 3 +), + +agg as ( + select + chain_used_for_cow, + chain_used_for_competitor, + competitor_project, + count(distinct address) as distinct_users_competitor, + sum(total_transactions_on_cow) as transactions_made_on_cow, + sum(total_volume_usd_on_cow) as total_volume_usd_on_cow, + sum(competitor_total_transactions) as transactions_made_on_competitor, + sum(competitor_total_volume_usd) as total_volume_usd_on_competitor + from + cow_protocol_target_users + left join all_competitor_transactions using (address) -- noqa: disable=L032 + group by 1, 2, 3 +) + +select + chain_used_for_cow, + chain_used_for_competitor, + competitor_project, + distinct_users_cow, + distinct_users_competitor, + transactions_made_on_cow, + total_volume_usd_on_cow, + transactions_made_on_competitor, + total_volume_usd_on_competitor +from + agg +left join users_per_chain_cow using (chain_used_for_cow) -- noqa: disable=L032