Query editor
/*This query retrieves the present amount of stETH liquidity in USD and the TVL in USD for the current date*/-- to retrieve daily amounts of (w)stETH involved in unwrapping and wrapping transactions-- for the further calculation of wstETH:stETHwith volumes AS (SELECTu.call_block_time AS time,"output_0" AS steth,"_wstETHAmount" AS wstethFROMlido_ethereum.WstETH_call_unwrap uWHERE"call_success" = TRUEUNION allSELECTu."call_block_time","_stETHAmount" AS steth,"output_0" AS wstethFROMlido_ethereum.WstETH_call_wrap uWHERE"call_success" = TRUE)-- to calculate the current rate of wstETH:stETH from CTE 'volumes', wsteth_rate AS (SELECT SUM(cast(steth AS DOUBLE)) / SUM(cast(wsteth AS DOUBLE)) AS rateFROMvolumes vWHERE date_trunc('day', v.time) = date_trunc('day', now()))SELECTSUM(liquidity_usd) AS liquidity_usd,SUM(tvl) AS tvl,SUM(steth_amount) as steth_amountFROM( --this subquery calculates the pared token reserve in USD and TVL in USD filtering for the current date-- negative reserves are a data glitch in the spell (e.g. curve pufETH:wstETH), clamp them to 0SELECTSUM(if(COALESCE(paired_token_usd_reserve, 0) < 0, 0, COALESCE(paired_token_usd_reserve, 0))) AS liquidity_usd,SUM(if(COALESCE(main_token_usd_reserve, 0) < 0, 0, COALESCE(main_token_usd_reserve, 0)) + if(COALESCE(paired_token_usd_reserve, 0) < 0, 0, COALESCE(paired_token_usd_reserve, 0))) AS tvl,SUM(CASEWHEN lower(main_token_symbol) = 'steth' THEN if(main_token_reserve < 0, 0, main_token_reserve)ELSE if(main_token_reserve < 0, 0, main_token_reserve) * (select rate from wsteth_rate)END) AS steth_amountFROMlido.liquidityWHEREcast(time AS DATE) = cast(now() AS DATE)UNION all--this subquery calculates the two pared token reserves in USD and tvl in USD filtering for the current dateSELECTSUM(paired_token_usd_reserve) + SUM(paired1_token_usd_reserve) AS liquidity_usd,SUM(main_token_usd_reserve) + SUM(paired_token_usd_reserve) + SUM(paired1_token_usd_reserve) AS tvl,