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 = 0x1495bc9e44Af1F8BCB62278D2bEC4540cF0C05ea OR token_bought_address = 0x1495bc9e44Af1F8BCB62278D2bEC4540cF0C05ea)AND block_time >= CAST('2024-03-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 = 0x1495bc9e44Af1F8BCB62278D2bEC4540cF0C05eaAND to IN (SELECT liquidity_pools FROM dex_pools)group by 1), erc20_out as (SELECT"from" as pool, sum(value) as amount_outFROM erc20_ethereum.evt_Transfer trWHERE tr.contract_address = 0x1495bc9e44Af1F8BCB62278D2bEC4540cF0C05eaAND "from" IN (SELECT liquidity_pools FROM dex_pools)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 = 0x1495bc9e44Af1F8BCB62278D2bEC4540cF0C05eaWHERE 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, sum(COALESCE(total_volume,0)) as total_volume, array_agg(dp.liquidity_pools) as pool_addresses-- concat('<a href="', get_chain_explorer.explorer, '/address/', cast( dp.liquidity_pools as varchar)