Query editor
with price_hourly as (SELECT date_trunc('hour', minute) as time, symbol, avg(price) as priceFROM prices.usdWHERE symbol in ('WETH', 'WBTC', 'USDC')AND blockchain = 'arbitrum'AND minute >= timestamp '2023-06-22 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 = 'WBTC', price, 0)) as btc_price,MAX(IF(symbol = 'USDC', price, 0)) as stables_priceFROM price_hourlyGROUP BY time),hlp_trading_fee as (SELECT time,supply.supply,if(lag(supply.supply) over (order by time) < supply, supply.supply, lag(supply.supply) over (order by time)) as max_supply,SUM(hlp_gained_fee_usd) OVER (ORDER BY time) as hlp_accum_fee_usdFROM (SELECT date_trunc('day', evt_block_time) as time,-- first week distribute 90% tradingFee to HLP-- following week distribute 65% tradingFee to HLPSUM(feeUsd) / 1e30 as trading_fee_usd,CASEWHEN date_trunc('day', evt_block_time) <= timestamp '2023-07-06' THEN SUM(feeUsd) * 0.9 / 1e30WHEN date_trunc('day', evt_block_time) <= timestamp '2024-03-07' THEN SUM(feeUsd) * 0.65 / 1e30ELSE SUM(feeUsd) * 0.5 / 1e30ENDas hlp_gained_fee_usdFROM hmx_arbitrum.TradeHelper_evt_LogSettleTradingFeeValueGROUP BY 1) tf LEFT JOIN (select distinctdate_trunc('day',evt_block_time) as t,last_value(supply) over (partition by date_trunc('day',evt_block_time) order by evt_block_time ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as supplyfrom ((select evt_block_time, aum, supply from hmx_arbitrum.LiquidityService_evt_AddLiquidity)union all(select evt_block_time, aum, supply from hmx_arbitrum.LiquidityService_evt_RemoveLiquidity))) supply on tf.time = supply.t),hlp_index_composition as (SELECT time,0.25 / eth_price as eth_amt,0.2 / btc_price as btc_amt,0.55 / stables_price as stables_amtFROM wrap_price_hourlyWHERE time = timestamp '2023-06-22 00:00'),hlp_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 hlp_index_composition h),hlp_eshmx_reward as (