Query editor
WITH data AS (SELECT block_time, block_number, tx_hash, tx_from, taker AS mev_bot, t.token_address, t.token_symbol, SUM(t.token_amount) AS token_amount_original--, SUM(t.token_amount*pu.price) AS usd_profit--, COUNT(aa.tx_hash) AS arb_transactionsFROM dex.atomic_arbitrages aaCROSS JOIN UNNEST(ARRAY[(token_sold_address, -token_sold_amount, token_sold_symbol), (token_bought_address, token_bought_amount, token_bought_symbol)]) AS t(token_address, token_amount, token_symbol)WHERE aa.blockchain='{{Blockchain}}'AND aa.block_time between CAST('2024-05-03 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC' and CAST('2024-05-04 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC'GROUP BY 1, 2, 3, 4, 5, 6, 7), aggregated_data AS (SELECT tx_from, block_number, mev_bot, SUM(d.token_amount_original*pu.price) AS usd_profit, COUNT(DISTINCT tx_hash) AS transactionsFROM data dINNER JOIN prices.usd_forward_fill pu ON pu.minute between CAST('2024-05-03 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC' and CAST('2024-05-04 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC'AND pu.blockchain='{{Blockchain}}'AND pu.contract_address=d.token_addressAND pu.minute=date_trunc('minute', d.block_time)GROUP BY 1, 2, 3HAVING SUM(d.token_amount_original*pu.price) > 0), distinct_mev_txs AS (SELECT DISTINCT tx_from, taker AS mev_bot, block_time, block_number, tx_hash, tx_indexFROM dex.atomic_arbitragesWHERE blockchain='{{Blockchain}}'AND block_time between CAST('2024-05-03 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC' and CAST('2024-05-04 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC'-- AND taker = 0x6b75d8AF000000e20B7a7DDf000Ba900b4009A80 ---!!!! Jared), distinct_mev_txs_with_miner AS (SELECT txs.mev_bot, txs.block_time, txs.block_number, txs.tx_hash, tx_index, b.miner AS builder, b.base_fee_per_gasFROM distinct_mev_txs txsINNER JOIN evms.blocks b ON b.blockchain='{{Blockchain}}'AND b.number=txs.block_numberAND b.time between CAST('2024-05-03 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC' and CAST('2024-05-04 00:00:00' AS TIMESTAMP) AT TIME ZONE 'UTC')