Query editor
with diesel_inflow AS (SELECTdate_trunc('day', evt_block_time) AS day,contract_address pool,SUM(CASE WHEN "from" = 0x0000000000000000000000000000000000000000 THEN cast(value as int256) ELSE 0 END)- SUM(CASE WHEN to = 0x0000000000000000000000000000000000000000 THEN cast(value as int256) ELSE 0 END) inflowFROMerc20_ethereum.evt_TransferWHEREcontract_address in (select pool from query_4150886 where version = 3)GROUP BY 1, 2),diesel_balance as (selectday,di.pool,sum(inflow) over (partition by di.pool order by day) balance,pu.underlying,pu.name pool_namefromdiesel_inflow di left join query_4150886 puon di.pool = pu.pool),pool_inflows as ((selectevt_block_time,contract_address token,to pool,cast(value as int256) AS valueFROM erc20_ethereum.evt_TransferWHERE contract_address in (select underlying from query_4150886)AND to in (select pool from query_4150886 where version = 3))union all(SELECTevt_block_time,contract_address token,"from" pool,-cast(value as int256) AS valueFROM erc20_ethereum.evt_TransferWHERE contract_address in (select underlying from query_4150886)AND "from" in (select pool from query_4150886 where version = 3))),pool_balance as (selectday,token,pool,sum(value) over (partition by token, pool order by day) balancefrom (selectdate_trunc('day',evt_block_time) day, token, pool, sum(value) valuefrom pool_inflows group by 1,2,3)),pool_balance_underlying as (select