Query editor
WITH v3_variablerate AS (SELECTdate_trunc('day',evt_block_time) AS time,id,AVG(prevBorrowRate / POWER(10, 18) * 365 * 24 * 60 * 60)*100 AS borrow_rateFROM morpho_blue_ethereum.MorphoBlue_evt_AccrueInterest aWHERE id = 0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41GROUP 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.borrow_rate,("Lido staking APR(instant)" / (1 - {{LTV}}) - borrow_rate / (1 - {{LTV}}) * {{LTV}}) as net_variable_lev_apyFROM oracles_data oLEFT JOIN v3_variablerate r ON o.time = r.time)SELECTtime,protocol_apr,