Query editor
with tokens as (-- (select 0x33349b282065b0284d756f0577fb39c158f935e6 as address, 'MPL' as token, 'Maple Finance' as protocol, '#' as underlying, 'ethereum' as chain)-- union all(select 0xfAbA6f8e4a5E8Ab82F62fe7C39859FA577269BE3 as address, 'ONDO' as token, 'Ondo Finance' as protocol, '#' as underlying, 'multi' as chain)union all(select 0xCA30c93B02514f86d5C86a6e375E3A330B435Fb5 as address, 'bIB01' as token, 'Backed Finance' as protocol, '#' as underlying, 'ethereum' as chain)union all(select 0xad6250f0BD49F7a1eB11063af2cE9F25B9597b0F as address, 'TBILL' as token, 'Open Eden' as protocol, '#' as underlying, 'ethereum' as chain)union all(select 0x96F6eF951840721AdBF46Ac996b59E0235CB985C as address, 'USDM' as token, 'Mountain Finance' as protocol, '#' as underlying, 'ethereum' as chain)union all(select 0x530824DA86689C9C17CdC2871Ff29B058345b44a as address, 'STBT' as token, 'Matrixport' as protocol, '#' as underlying, 'ethereum' as chain)),all_transfers as (select date_trunc('week', evt_block_time) as date,contract_address,sum(casewhen contract_address = 0xad6250f0BD49F7a1eB11063af2cE9F25B9597b0F then (cast(value as double) / 1e6)else (cast(value as double) / 1e18)end) as value,count(distinct "from") as usersfrom erc20_ethereum.evt_Transferwhere contract_address in (select address from tokens)group by 1, 2),all_trades as (select date_trunc('week', block_date) as date,project,token_bought_address,sum(amount_usd) as volume,count(*) as trade_countfrom dex.trades dexwhere token_bought_address in (select address from tokens)and blockchain in ('ethereum', 'polygon', 'bnb', 'gnosis')group by 1, 2, 3)-- select b.token,-- sum(a.value) as total_volume,-- sum(a.users) as total_users-- from all_transfers a-- left join tokens b on a.contract_address = b.address-- where a.date >= TIMESTAMP '2023-01-01'-- group by 1-- order by 1select b.token,array_agg(distinct t.project) as unique_dexes,sum(a.value) as total_volume,sum(a.users) as total_usersfrom all_transfers aleft join tokens b on a.contract_address = b.addressleft join all_trades t on t.token_bought_address = b.addresswhere a.date >= TIMESTAMP '2023-01-01'group by 1order by 1