Query editor
WITH pool_state AS (SELECTtotal_pt,total_sy,total_lp,liquidity_usd,total_tvl_usd,pt_discount,underlying_apy,implied_apy,yt_floating_apyFROM query_5939800WHERE timestamp = (SELECT MAX(timestamp) FROM query_5939800)),-- Calculate days until maturitymaturity_info AS (SELECTDATE '2025-12-10' as maturity_date,DATE_DIFF('day', CURRENT_DATE, DATE '2025-12-10') as days_to_maturity),-- Derive PT and SY prices from pool state WITH yield considerationderived_prices AS (SELECTps.*,mi.days_to_maturity,-- Current SY price from poolps.liquidity_usd / (ps.total_pt + ps.total_sy) as sy_price_current_usd,-- SY price at maturity (with accrued yield)ps.liquidity_usd / (ps.total_pt + ps.total_sy) * (1 + ps.underlying_apy * mi.days_to_maturity / 365) as sy_price_maturity_usd,-- PT current price (with discount)ps.liquidity_usd / (ps.total_pt + ps.total_sy) * (1 - ps.pt_discount) as pt_price_current_usd,-- PT price at maturity (converges to SY maturity price)ps.liquidity_usd / (ps.total_pt + ps.total_sy) * (1 + ps.underlying_apy * mi.days_to_maturity / 365) as pt_price_maturity_usdFROM pool_state psCROSS JOIN maturity_info mi),lp_supply AS (SELECTSUM(balance) as total_lp_supplyFROM tokens_ethereum.balances_dailyWHERE token_address = 0x56649da435f9a9a57ee9c4c06b728e4ba84fcc6bAND day = date_trunc('day', current_date)),RankedBalances AS (SELECTb.address,b.balance,ROW_NUMBER() OVER(ORDER BY b.balance DESC) AS rankFROM tokens_ethereum.balances_daily bWHERE token_address = 0x56649da435f9a9a57ee9c4c06b728e4ba84fcc6bAND b.day = date_trunc('day', current_date)AND b.balance > 0)