Query editor
with trading_fee as (select date_trunc('day', evt_block_time) as date_, sum(feeUsd) / 1e30 as feeUSD from hmx_arbitrum.TradeHelper_evt_LogSettleTradingFeeAmountgroup by date_trunc('day', evt_block_time))select pnl.date_ ,PnlValue - coalesce(usd, 0) - feeUSD as PnL_After_Fee,sum(PnlValue - coalesce(usd, 0) - feeUsd) over (order by pnl.date_) as Cumulative_PnL_After_Feefrom(select date_trunc('day',evt_block_time) as date_ ,sum(usd)/1e30 as PnlValue from((select evt_block_time, cast(usd as double) as usd from hmx_arbitrum.TradeHelper_evt_LogReceivedUnRealizedPnlValue)union all(select evt_block_time, -cast(usd as double) as usd from hmx_arbitrum.TradeHelper_evt_LogSettleUnRealizedPnlValue ))group by date_trunc('day',evt_block_time)) pnl left join-- Funds, reimbursed by HMX’s oracle provider, injected back into HLP(select date_trunc('day', evt_block_time) as date_, sum(amount * price.price / pow(10, price.decimals)) as usdfrom hmx_arbitrum.BotHandler_evt_LogInjectTokenToHlpLiquidity ijoin prices.usd price on price.contract_address = i.tokenand date_trunc('minute', i.evt_block_time) = date_trunc('minute', price.minute)group by date_trunc('day', evt_block_time), price.price, price.decimals) refund on pnl.date_ = refund.date_join trading_fee on pnl.date_ = trading_fee.date_