Query editor
WITH dex_liquidity AS (SELECTday,project,SUM(token_amount) AS token_amountFROM dex.liquidityWHERE token_symbol = 'rETH'GROUP BY day, project),-- Curve rETH-wstETH pool liquidity calculationcurve_liquidity AS (WITH liquidity_added AS (SELECTevt_block_time AS time,token_amounts[1] / 1e18 AS reth_amountFROM curvefi."rETHwstETH_evt_AddLiquidity"),liquidity_removed AS (SELECTevt_block_time AS time,-token_amounts[1] / 1e18 AS reth_amountFROM curvefi."rETHwstETH_evt_RemoveLiquidity"),liquidity_removed_as_reth AS (SELECTcall_block_time as time,-output_0 / 1e18 AS reth_amountFROM curvefi."rETHwstETH_call_remove_liquidity_one_coin"WHERE i = 0 -- Remove liquidity to rETHAND call_success = TRUE),reth_change_via_token_exchange AS (SELECTevt_block_time AS time,CASEWHEN sold_id = 0 THEN tokens_sold / 1e18WHEN bought_id = 0 THEN -tokens_bought / 1e18END AS reth_amountFROM curvefi."rETHwstETH_evt_TokenExchange"),liquidity_changes AS (SELECT * FROM liquidity_addedUNION ALLSELECT * FROM liquidity_removedUNION ALLSELECT * FROM liquidity_removed_as_rethUNION ALLSELECT * FROM reth_change_via_token_exchange),day_added AS (SELECTtime,DATE_TRUNC('day', time) + interval '1 day' AS day,SUM(reth_amount) OVER (ORDER BY time) AS total_reth