Query editor
WITHdex_pools as (SELECTproject, version, case when project = 'balancer' and version = '2' then 0xba12222222228d8ba445958a75a0704d566bf2c8 --same vault on all chains, holds tokens for all pools.else project_contract_address end as liquidity_pools, sum(case when block_time > now() - interval '7' day then amount_usd else null end) as seven_day_volume, sum(case when block_time > now() - interval '1' month then amount_usd else null end) as one_month_volume, sum(amount_usd) as total_volumeFROM dex.tradesWHERE blockchain = 'ethereum'AND (token_sold_address = 0xd6203889C22D9fe5e938a9200f50FDFFE9dD8e02 OR token_bought_address = 0xd6203889C22D9fe5e938a9200f50FDFFE9dD8e02)AND block_time >= CAST('2024-11-01' AS TIMESTAMP)AND block_time <= CAST('2031-01-01' AS TIMESTAMP)GROUP BY 1,2,3)--get balance of token right now, balances as (WITHerc20_in as (SELECTto as pool, sum(value) as amount_inFROM erc20_ethereum.evt_Transfer trWHERE tr.contract_address = 0xd6203889C22D9fe5e938a9200f50FDFFE9dD8e02AND to IN (SELECT liquidity_pools FROM dex_pools)AND evt_block_time <= CAST('2031-01-01' AS TIMESTAMP)group by 1), erc20_out as (SELECT"from" as pool, sum(value) as amount_outFROM erc20_ethereum.evt_Transfer trWHERE tr.contract_address = 0xd6203889C22D9fe5e938a9200f50FDFFE9dD8e02AND "from" IN (SELECT liquidity_pools FROM dex_pools)AND evt_block_time <= CAST('2031-01-01' AS TIMESTAMP)group by 1)SELECTerc20_in.pool, (cast(amount_in as double) - COALESCE(cast(amount_out as double), 0))/pow(10,COALESCE(tk.decimals, 18)) as balanceFROM erc20_inLEFT JOIN erc20_out ON erc20_out.pool = erc20_in.poolLEFT JOIN tokens.erc20 tk ON tk.blockchain = 'ethereum' AND tk.contract_address = 0xd6203889C22D9fe5e938a9200f50FDFFE9dD8e02WHERE cast(amount_in as double) - COALESCE(cast(amount_out as double), 0) > 0)--check balances, they seem too high given total supply limitSELECTdp.project, dp.version, sum(COALESCE(b.balance,0)) as total_liqudity, sum(COALESCE(seven_day_volume,0)) as seven_day_volume, sum(COALESCE(one_month_volume,0)) as one_month_volume