Query editor
/*This query calculates deposits and withdrawals by project over a specified number of days*/-- This CTE generate a list of project labeled by liquidity from materialized view 'dune.lido.result_eth_depositors_labels'with-- This CTE aggregates the total amount of ETH deposited by each project from the materilized view--`dune.lido.result_deposits_assigned_to_projects' over the specified number of daysdeposits_projects AS (SELECTcase when trim(name1) = '' then COALESCE(name, 'Unidentified') else name1 end as name,SUM(amount) AS amountFROMdune.lido.result_deposits_assigned_to_projectsWHEREdate_trunc('day', time) >= NOW() - interval '{{number_of_days}}' dayGROUP BY 1),-- This CTE selects the project and the amount of ETH withdrawn from the materilized view--`dune.lido.result_withdrawals_transactions_assigned_to_projects` over the specified number of daysallwithdrawals AS (SELECTcase when trim(project1) = '' then project else project1 end as project,withdrawn_principal AS amountFROMdune.lido.result_withdrawals_transactions_assigned_to_projects--dune.lido.result_1038304 --query_1038304WHEREdate_trunc('day', time) >= NOW() - interval '{{number_of_days}}' dayAND withdrawn_principal > 0),-- This CTE aggregates the total amount of ETH withdrawn by each project from CTE 'allwithdrawals'withdrawals_projects AS (SELECTproject AS name,SUM(amount) AS amountFROMallwithdrawalsGROUP BY1)-- final query combines data from CTE `deposits_projects` and CTE `withdrawals_projects` to calculate the net growth in ETH depositsSELECTCOALESCE(d.name, w.name) AS name,COALESCE(d.amount, 0) AS eth_deposited,COALESCE(w.amount, 0) AS eth_withdrawn,COALESCE(d.amount, 0) - COALESCE(w.amount, 0) AS eth_deposits_growthFROMdeposits_projects dfull OUTER JOIN withdrawals_projects w ON d.name = w.nameORDER BYeth_deposits_growth DESC