Query editor
WITH liquidity_added AS (SELECTdate_trunc('day', block_time) as day,SUM(eth_amount / (10^18)) as net_eth,SUM(token_amount / (10^18)) as net_tknFROM uniswap."Exchange_evt_AddLiquidity"LEFT JOIN ethereum."transactions" tx ON evt_tx_hash = tx.hashWHERE contract_address = '\x22d8432cc7aa4f8712a655fc4cdfb1baec29fca9'GROUP BY 1),liquidity_removed AS (SELECTdate_trunc('day', block_time) as day,SUM(-eth_amount / (10^18)) as net_eth,SUM(-token_amount / (10^18)) as net_tknFROM uniswap."Exchange_evt_RemoveLiquidity"LEFT JOIN ethereum."transactions" tx ON evt_tx_hash = tx.hashWHERE contract_address = '\x22d8432cc7aa4f8712a655fc4cdfb1baec29fca9'GROUP BY 1),tkn_bought AS (SELECTdate_trunc('day', block_time) as day,SUM(eth_sold / (10^18)) as net_eth,SUM(-tokens_bought / (10^18)) as net_tknFROM uniswap."Exchange_evt_TokenPurchase"LEFT JOIN ethereum."transactions" tx ON evt_tx_hash = tx.hashWHERE contract_address = '\x22d8432cc7aa4f8712a655fc4cdfb1baec29fca9'GROUP BY 1),eth_bought AS (SELECTdate_trunc('day', block_time) as day,SUM(-eth_bought / (10^18)) as net_eth,SUM(tokens_sold / (10^18)) as net_tknFROM uniswap."Exchange_evt_EthPurchase"LEFT JOIN ethereum."transactions" tx ON evt_tx_hash = tx.hashWHERE contract_address = '\x22d8432cc7aa4f8712a655fc4cdfb1baec29fca9'GROUP BY 1),all_events AS (SELECT *FROM liquidity_addedUNIONSELECT *FROM liquidity_removedUNIONSELECT *FROM tkn_boughtUNIONSELECT *FROM eth_bought)SELECTall_events.day,avg(p.price),SUM(net_eth) as eth_in_pool,sum(sum(net_eth)) over (order by all_events.day) as eth_balance,SUM(net_tkn) as tkn_in_pool,