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,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)),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 (SELECT * FROM query_3702253),hlp_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 HLP)((cast(aum as double) * 1.0 / 1e30) + hf.hlp_accum_fee_usd + coalesce(es.esHmx_usd, 0)) / (cast(supply as double) * 1.0 / 1e18)) as pricefrom((select evt_block_time, aum, supply from hmx_arbitrum.LiquidityService_evt_AddLiquidity)