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. */SELECTdt.block_date,dt.block_time,-- Shift block_time to next block pre-merge but not post-mergeCASE WHEN tx.block_number < 15537393 then tx1.block_time else tx.block_time END as block_time,CASEWHEN dt.token_bought_symbol = 'WETH' then -1WHEN dt.token_bought_symbol = 'PEPE' then 1END as swap_side,token_bought_amount,token_sold_amount,casewhen token_bought_symbol = 'PEPE' then token_sold_amount / token_bought_amountelse token_bought_amount / token_sold_amountend as price,dt.tx_hash,tx_from as signer,tx.gas_used * tx.gas_price / 1e18 as tx_cost_eth,tx.gas_used * tx.gas_price / 1e18 * casewhen token_bought_symbol = 'WETH' then token_sold_amount / token_bought_amountelse token_bought_amount / token_sold_amountend as tx_cost_usdFROMdex.trades dtINNER JOIN ethereum.transactions AS tx ON tx.hash = dt.tx_hashLEFT JOIN (SELECTblock_number,MIN(block_time) AS block_timeFROMethereum.transactionsWHEREblock_time >= cast({{START_DATE}} as timestamp)AND block_time < cast({{END_DATE}} as timestamp)GROUP BYblock_number) AS tx1 ON tx1.block_number = tx.block_number + 1WHEREblockchain = 'ethereum'AND token_pair = 'PEPE-WETH'