Query editor
WITH v3_variablerate AS (SELECTdate_trunc('day',evt_block_time) AS time,symbol,AVG(variableBorrowRate)/1e27*100 AS variable_rateFROM spark_protocol_ethereum.Pool_evt_ReserveDataUpdated aLEFT JOIN tokens.erc20 b ON a.reserve = b.contract_addressWHERE symbol in ('WETH')GROUP BY 1,2),calendar AS (with day_seq as(SELECT( sequence(cast('2021-04-30' as date),cast(now() as date), interval '1' day)) day )select days.dayfrom day_seqcross join unnest(day) as days(day)),shares as (selectpreTotalEther*1e27/preTotalShares as pre_share_rate,postTotalEther*1e27/postTotalShares as post_share_rate,*from lido_ethereum.steth_evt_TokenRebased),oracles_data as (--old oralceSELECT date_trunc('day',evt_block_time) AS time,cast(("postTotalPooledEther" - "preTotalPooledEther")* 365 * 24 * 60 * 60 /("preTotalPooledEther") as double)/timeElapsed * 100 as protocol_apr,cast(("postTotalPooledEther" - "preTotalPooledEther")* 365 * 24 * 60 * 60 /("preTotalPooledEther") as double)/timeElapsed * 0.9 * 100 as "Lido staking APR(instant)","postTotalPooledEther" / 1e18 AS pooled_ethFROMlido_ethereum.LegacyOracle_evt_PostTotalShareswhere "evt_block_time" <= cast('2023-05-16 00:00' as timestamp)--new V2 oracleunion allselect date_trunc('day',evt_block_time) as time,(365*24*60*60*(post_share_rate - pre_share_rate) / pre_share_rate / timeElapsed * 100) /0.9 as protocol_apr,365*24*60*60*(post_share_rate - pre_share_rate)/ pre_share_rate / timeElapsed * 100 as "Lido staking APR(instant)",cast(postTotalEther as double)/1e18from shares),variable_rate_table AS (SELECTo.time,o.protocol_apr,o."Lido staking APR(instant)",r.variable_rate,("Lido staking APR(instant)" / (1 - {{LTV}}) - variable_rate / (1 - {{LTV}}) * {{LTV}}) as net_variable_lev_apyFROM oracles_data oLEFT JOIN v3_variablerate r ON o.time = r.time)SELECTtime,