Query editor
WITHtrades AS (SELECTevt_block_time AS block_time,evt_block_number AS block_number,IF(isBuy, 'Buy', 'Sell') AS type,coreAmount,IF(isBuy,CAST(coreAmount AS INT256),- CAST(coreAmount AS INT256)) AS coreAmountDelta,(ethAmount / 1e18) / coreAmount AS corePriceETH,ethAmount / 1e18 AS volumeETH,protocolEthAmount / 1e18 AS feeETH,supply,trader,evt_tx_hash AS tx_hashFROMcipher_arbitrum.Cipher_evt_Trade),traderLeaderboard AS (SELECTtrader,SUM(coreAmountDelta) AS currentBalance,SUM(IF(type = 'Buy', coreAmount, CAST(0 AS UINT256))) AS coresBought,SUM(IF(type = 'Sell', coreAmount, CAST(0 AS UINT256))) AS coresSold,SUM(volumeETH) AS volumeETH,SUM(feeETH) AS feesPaidETH,COUNT(DISTINCT (tx_hash)) AS numberOfTrades,MIN(block_time) AS firstTradeDate,MAX(block_time) AS latestTradeDate,SUM(IF(type = 'Buy', volumeETH, 0)) AS totalBuyPriceETH,SUM(IF(type = 'Sell', volumeETH, 0)) AS totalSellPriceETHFROMtradesGROUP BYtrader)SELECTRANK() OVER (ORDER BYtotalSellPriceETH - totalBuyPriceETH DESC) AS traderRank,traderLeaderboard.*,totalSellPriceETH - totalBuyPriceETH as PnLFROMtraderLeaderboardGROUP BYtrader,currentBalance,coresBought,coresSold,volumeETH,feesPaidETH,numberOfTrades,firstTradeDate,latestTradeDate,totalBuyPriceETH,totalSellPriceETH