Query editor
with trades as (SELECT (SELECT price FROM prices.usd_latest where symbol = 'WETH' and blockchain = 'arbitrum') *sum(cast(token_bought_amount as DOUBLE)) / sum(cast(token_sold_amount_raw as DOUBLE) /1e18) as token_price, token_sold_address as token_addressFROM dex.tradeswhere blockchain = 'arbitrum'and token_sold_address != 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8and token_bought_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1and token_sold_address != 0x09e18590e8f76b6cf471b3cd75fe1a1a9d2b2c2band block_time > now() - interval '24' hourGROUP BY 2UNIONSELECT (SELECT price FROM prices.usd_latest where symbol = 'WETH' and blockchain = 'arbitrum') *sum(cast(token_sold_amount as DOUBLE)) / sum(cast(token_bought_amount_raw as DOUBLE) /1e18) as token_price, token_bought_address as token_addressFROM dex.tradeswhere blockchain = 'arbitrum'and token_bought_address != 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8and token_sold_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1and block_time > now() - interval '24' hourGROUP BY 2),filter as (SELECT sum(amount_usd) as volume, token_bought_address as token_address FROM dex.tradeswhere block_time > now() - interval '3' dayand blockchain = 'arbitrum'GROUP BY 2),latest_prices as (SELECT avg(token_price) as token_price, token_address FROM tradeswhere token_address != 0x09e18590e8f76b6cf471b3cd75fe1a1a9d2b2c2band token_address != 0x69b2cd28b205b47c8ba427e111dd486f9c461b57and token_price < 5000and token_address in (SELECT token_address FROM filter where volume > 100000)GROUP BY 2),balance_day as (SELECT sum(cast(value as DOUBLE)/1e18) as value, contract_address, "to" as address, date_trunc('day', evt_block_time) as day FROM erc20_arbitrum.evt_Transferwhere contract_address in (SELECT token_address FROM latest_prices)GROUP BY 2, 3, 4UNIONSELECT sum(-cast(value as DOUBLE)/1e18) as value, contract_address, "from" as address, date_trunc('day', evt_block_time) as day FROM erc20_arbitrum.evt_Transferwhere contract_address in (SELECT token_address FROM latest_prices)GROUP BY 2, 3, 4),balance as (SELECT sum(value) as value, contract_address, address, min(day) as created_date FROM balance_dayGROUP BY 2, 3),balance_labelled as (SELECT a.value * b.token_price as usd_balance, a.address as address, a.created_date FROM balance a left join latest_prices bon a.contract_address = b.token_address),tabulate as (SELECT sum(usd_balance) as usd_balance, address, created_date FROM balance_labelledGROUP BY 2, 3),tabulated as (SELECT * FROM tabulatewhere usd_balance > {{Min Balance}} ),eth_transfers as (select "from" as address, cast(value as double) / -1e18 as amount from arbitrum.traceswhere call_type = 'call'and success = trueand cast(value as double) > 0and "from" in (SELECT address FROM tabulated)