Query editor
/* WSOLAddress: 'So11111111111111111111111111111111111111112' *//* FeeWallet: 'ZG98FUCjb8mJ824Gbs6RsgVmr1FhXb2oNiJHa2dwmPd' *//* FirstTradeTimestamp: TIMESTAMP '2023-08-17' */WITHbotTradesWithFees AS (SELECTblock_date,--type,amount_usd,IF(token_sold_address = 'So11111111111111111111111111111111111111112','Buy','Sell') AS type,fee_usd,user,project_contract_address,tx_idFROMbonkbot_solana.bot_tradesWHEREis_last_trade_in_transaction = true -- This prevents over counting for multi-hop trades and excludes tax distributions),firstUserOccurrences AS (SELECTuser,MIN(block_date) AS firstTradeDateFROMbotTradesWithFeesGROUP BYuser), final as (SELECTblock_date,SUM(amount_usd) AS totalVolumeUSD,COUNT(DISTINCT (botTradesWithFees.user)) AS numberOfUsers,COALESCE(COUNT(DISTINCT (firstUserOccurrences.user)), 0) AS numberOfNewUsers,SUM(IF("type" = 'Buy', amount_usd, 0)) AS buyVolumeUSD,SUM(IF("type" = 'Sell', amount_usd, 0)) AS sellVolumeUSD,SUM(fee_usd) AS feesUSD,COUNT(DISTINCT (tx_id)) AS numberOfTrades,COUNT(DISTINCT (project_contract_address)) AS numberOfPairs,COUNT(DISTINCT (botTradesWithFees.user)) - COALESCE(COUNT(DISTINCT (firstUserOccurrences.user)), 0) AS numberOfReturningUsers,SUM(COALESCE(COUNT(DISTINCT (firstUserOccurrences.user)), 0)) OVER (ORDER BYblock_date) AS cumulative_numberOfNewUsersFROMbotTradesWithFeesLEFT OUTER JOIN firstUserOccurrences ON (botTradesWithFees.user = firstUserOccurrences.userAND botTradesWithFees.block_date = firstUserOccurrences.firstTradeDate)GROUP BYblock_dateORDER BYblock_date DESC