Query editor
with arb_asset as (select id, decimals, isStable, symbol from mux_arbitrum.LiquidityPoolHop1_evt_AddAsset), last_price AS (SELECT symbol, CAST(json_query(args,'lax $.assetPrice') AS DECIMAL(38, 0))/1e18 as price FROM mux_arbitrum.LiquidityPoolHop1_evt_OpenPosition as ajoin arb_asset as b on a.assetId = b.idWHERE (assetId, evt_block_time) IN (SELECT assetId, max(evt_block_time) FROM mux_arbitrum.LiquidityPoolHop1_evt_OpenPosition GROUP BY 1)), arb_pnl_data as (select CAST(json_query(args,'lax $.profitAssetId') AS integer) as profitAssetId,CAST(json_query(args,'lax $.hasProfit') AS boolean) as hasProfit,CAST(json_query(args,'lax $.pnlUsd') AS DECIMAL(38, 0))/1e18 as pnlUsd,(CAST(json_query(args,'lax $.profitAssetPrice') AS DECIMAL(38, 0))/1e18) as profitAssetPrice,CAST(json_query(args,'lax $.collateralId') AS integer) as collateralAssetId,(CAST(json_query(args,'lax $.collateralPrice') AS DECIMAL(38, 0))/1e18) as collateralAssetPricefrom mux_arbitrum.LiquidityPoolHop1_evt_ClosePositionUNION ALLselect CAST(json_query(args,'lax $.profitAssetId') AS integer) as profitAssetId,CAST(json_query(args,'lax $.hasProfit') AS boolean) as hasProfit,CAST(json_query(args,'lax $.pnlUsd') AS DECIMAL(38, 0))/1e18 as pnlUsd,(CAST(json_query(args,'lax $.profitAssetPrice') AS DECIMAL(38, 0))/1e18) as profitAssetPrice,CAST(json_query(args,'lax $.collateralId') AS integer) as collateralAssetId,(CAST(json_query(args,'lax $.collateralPrice') AS DECIMAL(38, 0))/1e18) as collateralAssetPricefrom mux_arbitrum.LiquidityPoolHop1_evt_Liquidate), data as (select b.symbol, ((mlpAmount/1e18) * (mlpPrice/1e18) / (tokenPrice/1e18)) as amount from mux_arbitrum.LiquidityPoolHop1_evt_AddLiquidity as ajoin arb_asset as b on a.tokenId = b.idUNION ALLselect b.symbol, (-(mlpAmount/1e18) * (mlpPrice/1e18) / (tokenPrice/1e18)) as amount from mux_arbitrum.LiquidityPoolHop1_evt_RemoveLiquidity as ajoin arb_asset as b on a.tokenId = b.idUNION ALLselect b.symbol, -(rawAmount0/POWER(10, b.decimals)) as amount from mux_arbitrum.LiquidityPoolHop1_evt_Rebalance as ajoin arb_asset as b on a.tokenId0 = b.idUNION ALLselect b.symbol, rawAmount1/POWER(10, b.decimals) as amount from mux_arbitrum.LiquidityPoolHop1_evt_Rebalance as ajoin arb_asset as b on a.tokenId1 = b.idUNION ALLselect b.symbol, -pnlUsd/profitAssetPrice as amount from arb_pnl_data as ajoin arb_asset as b on a.profitAssetId = b.id WHERE a.hasProfitUNION ALLselect b.symbol, pnlUsd/collateralAssetPrice as amount from arb_pnl_data as ajoin arb_asset as b on a.collateralAssetId = b.id WHERE not a.hasProfit), data1 as (select symbol, sum(amount) as amount from data group by symbol)select sum(amount*coalesce(price, 1)) from data1 left join last_price on data1.symbol = last_price.symbol