Query editor
-- calc daily income for GLP holders by subtracting 1% keeper cost from protocol revenue and multiplying the result by 70%-- the result excludes esGMX rewards.with daily_glp_income as (select day, (revenue * 0.99 * 0.7) as glp_income_usdfrom query_2649580 -- daily revenue),-- join with GLP daily tvl table and calculate cumulative income, APR, avg APR, and median APRdaily_glp_yield as (select tb1.day, glp_tvl, glp_income_usd,sum(glp_income_usd) over(order by tb1.day) as glp_cumu_income,-- calc APRglp_income_usd/glp_tvl * 365 as glp_apr,avg(glp_income_usd/glp_tvl * 365) over(order by tb1.day) as glp_avg_apr,approx_percentile(glp_income_usd/glp_tvl * 365, 0.5) over(order by tb1.day) as glp_med_apr,-- -- calc APY-- pow(1 + glp_income_usd/glp_tvl, 365) - 1 as glp_apy,-- multiply by 100 for counter displayglp_income_usd/glp_tvl * 365 * 100 as glp_apr_times100,avg(glp_income_usd/glp_tvl * 365 * 100) over(order by tb1.day) as glp_avg_apr_times100,approx_percentile(glp_income_usd/glp_tvl * 365 * 100, 0.5) over(order by tb1.day) as glp_med_apr_times100from daily_glp_income tb1join query_1065619 tb2 -- GLP daily net dollar flow and tvlon tb1.day = tb2.day)select * from daily_glp_yield-- where day > cast('2021-08-31' as timestamp) -- 1st day has tiny amount of GLP and fees but huge apr, which makes avg daily apr artificially bigwhere day > cast('2021-09-08' as timestamp) -- drop data between 2021-08-31 (inception) and 2021-09-08 cuz data in week 1 are outliers (for example, huge daily APRs that we don't get when protocol matures)