Query editor
with dex_trade as (selectblockchain,block_time,tx_from,tx_hash,cast(token_bought_amount_raw as double) as token_bought_amount_raw,token_bought_amount,token_bought_address,cast(token_sold_amount_raw as double) as token_sold_amount_raw,token_sold_amount,token_sold_address,amount_usdfrom dex.tradesunionselectblockchain,block_time,tx_from,tx_hash,cast(token_bought_amount_raw as double) as token_bought_amount_raw,token_bought_amount,token_bought_address,cast(token_sold_amount_raw as double) as token_sold_amount_raw,token_sold_amount,token_sold_address,amount_usdfrom dex_aggregator.trades),dex_price as (/* selectdate_trunc('{{Time}}', minute) as dayt,avg(price) as pricesfrom prices.usdwhere contract_address = {{Contract}}and minute >= now() - interval '{{Timeframe}}' daygroup by 1 */selectdate_trunc('{{Time}}', block_time) as dayt,avg(amount_usd / (cast(token_bought_amount_raw as double) / pow(10, {{decimals}}))) as pricesfrom dex_tradewhere token_bought_address = {{Contract}}and block_time >= now() - interval '{{Timeframe}}' dayand blockchain = '{{Blockchain}}'group by 1),transfer as (selectdt,sum(amount) as netflowfrom (selectdate_trunc('{{Time}}', evt_block_time) as dt,cast(value as double) / pow(10, {{decimals}}) as amountfrom erc20_{{Blockchain}}.evt_Transfer ajoin tokens.erc20 b on a.contract_address = b.contract_address and b.blockchain = '{{Blockchain}}'where to = {{Wallet}}