Query editor
-- Cum. Position P&L: CumSum of realized pnl for each position/leg (positionId)-- Cum. Total P&L: CumSum of realized pnl for each position/leg (positionId) minus fees paid to GMX on each tx-- Cum. Overall P&L: Cum. Total P&L plus Open/Close/Edit fees paid to Pear on each txWITH tokens AS(SELECT contract_address, symbol FROM tokens.erc20 WHERE blockchain = 'arbitrum'),user_adapters AS(SELECT DISTINCT BYTEARRAY_SUBSTRING(topic2, 13, 20) AS adapterAddress, BYTEARRAY_SUBSTRING(topic1, 13, 20) AS positionHolderFROM arbitrum.logs WHERE topic0 = 0x8ddf8b8ac039281a9cf1c4c80ed55d3499e6aae6d788f56e8c8c17cb64d8f615 -- evt_SetRefereeFeeAmount),user_positions AS -- ID(SELECT contract_address, evt_tx_hash, evt_index, evt_block_time,account,collateralToken,collateralDelta/1e30 AS collateralDelta,fee/1e30 AS fee,isLong,price/1e30 AS price,indexToken,IF(event = 'DecreasePosition', -(sizeDelta/1e30), sizeDelta/1e30) AS sizeDelta,"key",eventFROM (SELECT *, 'IncreasePosition' AS event FROM gmx_arbitrum.Vault_evt_IncreasePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03'UNION ALLSELECT *, 'DecreasePosition' AS event FROM gmx_arbitrum.Vault_evt_DecreasePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03')WHERE account IN (SELECT DISTINCT BYTEARRAY_SUBSTRING(topic2, 13, 20) AS adapter -- has leading zeros in address so can't use LTRIMFROM arbitrum.logsWHERE topic0 = 0xeccedcc6368d8acccba7ee32f84daeecf7350e56a501ad1438a1b417053c0fd0 -- PositionOpened--AND contract_address = 0x1DDCa7eaec57d24561e3Ba9A5A0c043868127018)ORDER BY evt_block_time DESC, evt_index DESC),position_details AS -- IDUC: user positions + position details(SELECT id.*,uc.averagePrice/1e30 AS averagePrice,uc.collateral/1e30 AS collateral,uc.entryFundingRate,uc.realisedPnl/1e30 AS realisedPnl,uc.reserveAmount,uc.size/1e30 AS size,uc.event AS uc_eventFROM user_positions idINNER JOIN (SELECT *, 'UpdatePosition' AS event FROM gmx_arbitrum.Vault_evt_UpdatePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03'UNION ALLSELECT *, 'ClosePosition' AS event FROM gmx_arbitrum.Vault_evt_ClosePositionWHERE evt_block_time >= TIMESTAMP '2023-10-03'