Query editor
with price_hourly as (SELECT date_trunc('hour', minute) as time, symbol, avg(price) as priceFROM prices.usdWHERE symbol in ('WETH', 'cbBTC', 'USDC')AND blockchain = 'base'AND minute >= timestamp '2024-12-31 00:00'GROUP BY date_trunc('hour', minute), symbol),wrap_price_hourly as (SELECT time,MAX(IF(symbol = 'WETH', price, 0)) as eth_price,MAX(IF(symbol = 'cbBTC', price, 0)) as btc_price,MAX(IF(symbol = 'USDC', price, 0)) as stables_priceFROM price_hourlyGROUP BY time),flp_trading_fee as (SELECT time,SUM(flp_gained_fee_usd) OVER (ORDER BY time) as flp_accum_fee_usdFROM (SELECT date_trunc('day', evt_block_time) as time,SUM(feeUsd) / 1e30 as trading_fee_usd,SUM(feeUsd) * 0.45 / 1e30 as flp_gained_fee_usd -- Fixed 45% to FLPFROM flexperp_base.TradeHelper_evt_LogSettleTradingFeeValueGROUP BY 1)),flp_index_composition as (SELECT time,0.20 / eth_price as eth_amt, -- 20% ETH0.40 / btc_price as btc_amt, -- 40% cbBTC0.40 / stables_price as stables_amt -- 40% USDC (0x833589fcd6edb6e08f4c7c32d4f71b54bda02913)FROM wrap_price_hourlyWHERE time = timestamp '2024-12-31 00:00'),flp_index_price as (SELECT p.time,(p.eth_price * h.eth_amt) + (p.btc_price * h.btc_amt) + (p.stables_price * h.stables_amt) as priceFROM wrap_price_hourly pCROSS JOIN flp_index_composition h),flp_esfdx_reward as (SELECT * FROM query_4704523),flp_fee_price as (select evt_block_time as time,(cast(supply as double) * 1.0 / 1e18) as supply,IF((cast(supply as double) * 1.0 / 1e18) < 5000,1.0, -- ignore price when low supply (< 5000 FLP)((cast(aum as double) * 1.0 / 1e30) + ff.flp_accum_fee_usd + coalesce(es.esFdx_usd, 0)) / (cast(supply as double) * 1.0 / 1e18)) as pricefrom((select evt_block_time, aum, supply from flexperp_base.LiquidityService_evt_AddLiquidity)union all(select evt_block_time, aum, supply from flexperp_base.LiquidityService_evt_RemoveLiquidity)) hleft join flp_trading_fee ff ON date_trunc('day', h.evt_block_time) = ff.timeleft join flp_esfdx_reward es ON date_trunc('day', h.evt_block_time) = es.timewhere cast(supply as double) > 0order by evt_block_time desc