Query editor
with timeframe as (selectcasewhen '{{Granularity}}' = 'monthly' then date('2020-01-01')when '{{Granularity}}' = 'weekly' then now() - interval '1' yearwhen '{{Granularity}}' = 'daily' then now() - interval '3' monthend as start_date,casewhen '{{Granularity}}' = 'monthly' then 'month'when '{{Granularity}}' = 'weekly' then 'week'when '{{Granularity}}' = 'daily' then 'day'end as interval),stable AS (SELECTcontract_address,decimals,case when symbol='PAX' then 'USDP'when symbol='UST' then 'USTC'else symbol end as symbolFROM tokens.erc20WHERE contract_address IN (select distinct address from query_1879804 where chain = 'ethereum' and address <> 0xbc6da0fe9ad5f3b0d58160288917aa56653660e9)and symbol <> 'ALUSD'and blockchain = 'ethereum'unionselect address, 18 as decimals, stablecoin as symbol from query_1879804 where stablecoin = 'GHO'unionselect address, 6 as decimals, stablecoin as symbol from query_1879804 where stablecoin = 'PYUSD'unionselect address, 18 as decimals, stablecoin as symbol from query_1879804 where stablecoin = 'FDUSD'unionselect address, 18 as decimals, stablecoin as symbol from query_1879804 where stablecoin = 'sDAI'),raw_amount AS (SELECTDATE_TRUNC('day', evt_block_time) AS day,a.contract_address,symbol,SUM(value/power(10,decimals)) AS txn_amountFROM stable a left joinerc20_ethereum.evt_Transfer bon a.contract_address=b.contract_addresswhere evt_block_time >= (select start_date from timeframe)group by 1,2,3),users AS (SELECTDATE_TRUNC((select interval from timeframe), evt_block_time) AS time,a.contract_address,symbol,count(distinct "from") AS active_addressFROM stable a left joinerc20_ethereum.evt_Transfer bon a.contract_address=b.contract_addresswhere evt_block_time >= (select start_date from timeframe)group by 1,2,3),