Query editor
WITH dex_vol AS(SELECTrow_number() OVER (ORDER BY date_trunc('month', block_date) ASC) AS seq, date_trunc('month', block_date) as month, SUM(amount_usd) as swap_volume, SUM(SUM(amount_usd)) over (ORDER BY date_trunc('month', block_date)) AS cumulative_swap_volumeFROM dex.tradesWHERE block_date >= CAST('2021-01-01 00:00' AS timestamp)AND block_date <= CAST('2023-09-30 00:00' AS timestamp)GROUP BY 2), dex_swaps AS (SELECTrow_number() OVER (ORDER BY date_trunc('month', block_date) ASC) AS seq, date_trunc('month', block_date) as month, COUNT(tx_hash) as swap_countFROM dex.tradesWHERE block_date >= CAST('2021-01-01 00:00' AS timestamp)AND block_date <= CAST('2023-09-30 00:00' AS timestamp)GROUP BY 2), cex_vol AS (SELECTrow_number() OVER (ORDER BY month ASC) AS seq, month, cex_volume_monthly AS swap_volumeFROM dune."0b04".dataset_cex_vol_monthly), renegade_revenue_bull AS (SELECTdv.seq AS seq, dv.month AS month, dv.swap_volume AS dex_vol, cv.swap_volume AS cex_vol, (((dv.swap_volume + cv.swap_volume) * .3) * .0002) as revenue_bull -- capturing 2bps fee on 30% of Dex & CEX vol, SUM(((dv.swap_volume + cv.swap_volume) * .3) * .0002) over (ORDER BY dv.month ASC) AS cumulative_revenue_bullFROM dex_vol AS dvJOIN cex_vol AS cv ON dv.seq = cv.seqWHERE dv.month >= CAST('2021-01-01 00:00' AS timestamp)AND dv.month <= CAST('2023-09-30 00:00' AS timestamp)), renegade_revenue_base AS (SELECTdv.seq AS seq, dv.month AS month, (((dv.swap_volume + cv.swap_volume) * .1) * .0002) as revenue_base -- capturing 2bps fee on 10% of Dex & CEX vol, SUM(((dv.swap_volume + cv.swap_volume) * .1) * .0002) over (ORDER BY dv.month ASC) AS cumulative_revenue_baseFROM dex_vol AS dvJOIN cex_vol AS cv ON dv.seq = cv.seqWHERE dv.month >= CAST('2021-01-01 00:00' AS timestamp)AND dv.month <= CAST('2023-09-30 00:00' AS timestamp)), renegade_revenue_bear AS (SELECTdv.seq AS seq