Query editor
/* Success! If you're still running into issues, check out https://dune.com/docs/query/syntax-differences/ or reach out in the #dune-sql Discord channel. */SELECT*,CAST(a.fees AS DOUBLE) + i.totalFundingPayment + e.repegRevenue + b.total_liquidation_fees + f.updateKRevenue - CAST(b.liquidation_bad_debt AS DOUBLE) as netRevenue,h.stakingPoolBalance - g.stakingPrincipal as stakingReward,insuranceFundBalance + h.stakingPoolBalance as totalbalanceFROM(SELECTCOUNT(DISTINCT (trader)) AS unique_users,SUM(positionNotional) / POWER(10, 18) AS volume,COUNT(*) AS total_trades,SUM(fee) / POWER(10, 18) AS fees,SUM(realizedPnl) / POWER(10, 18) AS realizedPnlFROMtribe3_arbitrum.ClearingHouse_evt_PositionChangedWHEREcontract_address = 0x01b6407ADf740d135ddF1eBDD1529407845773F3) AS aINNER JOIN (SELECTSUM(positionNotional / POWER(10, 18)) AS total_liquidations,COUNT(*) AS total_liquidation_count,SUM(feeToInsuranceFund / POWER(10, 18)) AS total_liquidation_fees,SUM(badDebt / 1e18) AS liquidation_bad_debtFROMtribe3_arbitrum.ClearingHouse_evt_PositionLiquidatedWHEREcontract_address = 0x01b6407ADf740d135ddF1eBDD1529407845773F3) AS b ON TRUEINNER JOIN (SELECT total AS open_interest FROM query_2418877 ORDER BY time DESC LIMIT 1) AS c ON TRUEINNER JOIN (SELECTSUM((positionNotional / POWER(10, 18)) * price) AS volume_usdFROMtribe3_arbitrum.ClearingHouse_evt_PositionChanged AS aINNER JOIN (SELECT*FROMprices.usdWHEREcontract_address = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1) AS d ON DATE_TRUNC('minute', a.evt_block_time) = d.minute) ON TRUEINNER JOIN (SELECTSUM(- cost / POWER(10, 18)) AS repegRevenueFROMtribe3_arbitrum.ClearingHouse_evt_RepegWHEREcontract_address = 0x01b6407ADf740d135ddF1eBDD1529407845773F3) AS e ON TRUEINNER JOIN (SELECTSUM(- cost / POWER(10, 18)) AS updateKRevenueFROMtribe3_arbitrum.ClearingHouse_evt_UpdateK