Query editor
/* ===================================================================================================================Pendle TVL and Revenue MonthlyA Demonstration of the calculation of Pendle TVL and Revenue metricsDetailed explanations are available in the dependent query.Note:This data doesn't match the official page https://app.pendle.finance/vependle/overviewbecause the official page isn’t calculated by natural months.=================================================================================================================== */with month_last_ds AS (SELECTdate_trunc('month', ds) AS month,MAX(ds) AS last_dsFROM dune.p_team.result_pendle_market_tvl_tracker -- materialized view of query_5530935, refreshed daily at around 1:00 am UTCWHERE ds != current_dateGROUP BY 1), monthly_tvl as (SELECTm.month,SUM(t.sy_value_in_usd) AS pendle_tvl -- TVL on that month’s final recorded dayFROM month_last_ds mJOIN dune.p_team.result_pendle_market_tvl_tracker t -- materialized view of query_5530935, refreshed daily at around 1:00 am UTCON date_trunc('month', t.ds) = m.monthAND t.ds = m.last_dsGROUP BY 1), monthly_revenue as (select date_trunc('month', ds) as month,sum(yt_fees_in_usd) as yt_fees_in_usd,sum(amm_swap_fees_in_usd) as amm_swap_fees_in_usd,sum(limit_order_fees_in_usd) as limit_order_fees_in_usd,sum(other_fees_in_usd) as other_fees_in_usd,sum(yt_fees_revenue_in_usd) as yt_fees_revenue_in_usd,sum(amm_swap_fees_revenue_in_usd) as amm_swap_fees_revenue_in_usd,sum(limit_order_fees_revenue_in_usd) as limit_order_fees_revenue_in_usd,sum(other_fees_revenue_in_usd) as other_fees_revenue_in_usdfrom dune.p_team.result_pendle_revenue_tracker daily_revenue -- materialized view of query_5533886, refreshed daily at around 1:00 am UTCgroup by 1), monthly_volume as (select date_trunc('month', ds) as month,sum(amm_sy_volume_in_usd) as amm_volume_in_usd,sum(limit_order_sy_volume_in_usd) as limit_order_volume_in_usd,sum(amm_sy_volume_in_usd) + sum(limit_order_sy_volume_in_usd) as volume_in_usdfrom (select ds, 0 as amm_sy_volume_in_usd, limit_order_sy_volume_in_usdfrom dune.p_team.result_pendle_limit_order_notional_trading_volume_by_chain_and_market -- materialized view of query_5547427, refreshed daily at around 1:00 am UTCunion allselect ds, amm_sy_volume_in_usd, 0 as limit_order_sy_volume_in_usdfrom dune.p_team.result_pendle_amm_notional_trading_volume_by_chain_and_market -- materialized view of query_5547253, refreshed daily at around 1:00 am UTC)group by 1)select monthly_tvl.month,monthly_tvl.pendle_tvl,monthly_revenue.yt_fees_in_usd,monthly_revenue.amm_swap_fees_in_usd,monthly_revenue.limit_order_fees_in_usd,monthly_revenue.other_fees_in_usd,