Query editor
--Copy of this: https://dune.xyz/queries/119229/240883--But with a parameter to focus on one project.WITHdate_range AS (SELECTcast(DATE_TRUNC('{{3 Time Granularity}}',LEAST(now(),cast('{{4 End Date}}' as timestamp))- interval '6' month) as timestamp) AS start_time,cast(DATE_TRUNC('{{3 Time Granularity}}',LEAST(now(),cast('{{4 End Date}}' as timestamp))- interval '6' month - interval '31' day) as timestamp) AS cohort_start_time,cast(cast('{{4 End Date}}' as timestamp) + (CASE WHEN '{{3 Time Granularity}}' = 'hour' --to be inclusive of the end dateTHEN interval '1' hour ELSE interval '1' dayEND) as timestamp) AS end_time_map,cast(DATE_TRUNC('{{3 Time Granularity}}',LEAST(now(),cast('{{4 End Date}}' as timestamp))) as timestamp)AS end_time_now,cast('{{4 End Date}}' as timestamp) AS end_time), gs_range AS (with seq as (SELECTsequence((SELECT cohort_start_time FROM date_range), (SELECT end_time_now FROM date_range),interval '1' {{3 Time Granularity}}) as time_pd)SELECTdays.time_pds as dtsFROM seqCROSS JOIN unnest(time_pd) as days(time_pds) --this is just doing explode like in spark sql), op_contracts AS (SELECT *,CASE--handle for kwenta (synthetix contracts, but were requested to be mapped differently)-- WHEN LOWER('{{1 Project Name}}') = 'kwenta' AND contract_project = 'Synthetix'-- AND (contract_name LIKE '%FuturesMarket%' OR contract_name LIKE '%SynthExchange%') THEN 1WHEN LOWER(COALESCE(contract_project,token_symbol)) = LOWER('{{1 Project Name}}') THEN 1ELSE 0END AS is_same_projectFROM contracts.contract_mapping gWHERE is_self_destruct = false and blockchain = 'optimism')