Query editor
with stables as (select *from query_3213110),exclude as (select tx_hash,token_pair,amount_usd,token_sold_amountfrom dex.tradeswhere amount_usd > 1000000000or token_pair is null),dex as (select *from dex.tradeswhere tx_hash not in (select distinct tx_hash from exclude)),balances as (select date, stables.symbol, sum(volume) as volumefrom (select date(block_date) as date,token_bought_address as symbol,sum(amount_usd) as volumefrom dexwhere token_bought_address in (select distinct address from stables)or token_sold_address in (select distinct address from stables)and date_trunc('day', block_date) >= date_trunc('day', now() - interval '3' year)and token_bought_symbol not in ('TBTC','WIRTUAL','WHALE','aBNBc') -- weird pricing, honestly might as well remove binance entirelyand token_sold_symbol not in ('TBTC','WIRTUAL','WHALE','aBNBc')and token_pair <> 'BUSD-FTM'group by 1, 2union allselect date(block_date) as date,token_sold_address as symbol,sum(amount_usd) as volumefrom dexwhere token_bought_address in (select distinct address from stables)or token_sold_address in (select distinct address from stables)and date_trunc('day', block_date) >= date_trunc('day', now() - interval '3' year)and token_bought_symbol not in ('TBTC','WIRTUAL','WHALE','aBNBc') -- weird pricing, honestly might as well remove binance entirelyand token_sold_symbol not in ('TBTC','WIRTUAL','WHALE','aBNBc')and token_pair <> 'BUSD-FTM'group by 1, 2) kiwileft join stables on kiwi.symbol = stables.addressgroup by 1, 2)select date_trunc('week', cast(date as TIMESTAMP)) as date,symbol,sum(volume) as volumefrom balanceswhere date >= date(now()) - interval '2' year