Query editor
-- EKU-945: per-transaction context for Ekubo Core v3 swaps in MEVCapture and matched static pools (Ethereum)-- Grain: one row per transaction containing >=1 in-scope Ekubo swap. Window: {{start}} <= block_date < {{end}}WITH ek AS (SELECT tx_hash, block_numberFROM ethereum.logsWHERE contract_address = 0x00000000000014aa86c5d3c41765bb24e11bd701AND topic0 IS NULL AND bytearray_length(data) = 116AND block_date >= date '{{start}}' AND block_date < date '{{end}}'AND bytearray_substring(data, 21, 32) IN (0x6fde3244f6fa747ae318aba6e982a4281febad4d22e3b134aa299a83a951895d,0xcda0a032de721efa74d07583c5ee137ea0d92763d73350a2102dcb2213fb7af6,0xfc30256b8955637d82d5ec8057a164927c3460fe8926f4b590fad857ce47d6f9,0x99a3b33ada97242c58fb31d884aa3b8c69d8fac6db3d6631e9336d1baadd6718,0x41b349297d536f7bf7beb64a6ee21472c0accf119554ce17062a0bec5759d6ef,0x49f4744cd4e8d49b180c7db20522e9053a030cd02f94a276403b2e361eed683f,0x4a619b24ff31bbeae86503d0321898c9cb3f07bc32097749ee0622d5e9b78d6f,0x4adbefdd73fe667a8ca4f5dd47b457d649e38e94351e97a973a20d8c7e75caf6,0x4fde6cbf993f4461dc9ea3501f6eb5537c58182f67f2116afae192a7156d7124,0xf0e95651d7ebbee146b6167083c527ef565c610ccc9df806d24755e50011bb7f,0x77e86b8f5da17873d7bdd70efc68a06dd3edc1d6e36b5bd65ff45eece33a31e4,0xb89fdd4fd0d3c76a4fd33d668df345c590e66a33a38d33d1a5fce19b441f31a1)GROUP BY 1, 2), tx AS (SELECT t.hash AS tx_hash, t.block_number, t."from" AS tx_from, t."to" AS tx_to, t.valueFROM ethereum.transactions t JOIN ek ON t.hash = ek.tx_hash AND t.block_number = ek.block_numberWHERE t.block_date >= date '{{start}}' AND t.block_date < date '{{end}}')SELECT tx.tx_hash, tx.tx_from, tx.tx_to, tx.value > 0 AS has_value,count_if(l.topic0 IN (0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822,0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67,0x40e9cecb9f5f1f1c5b9c97dec2917b7ee92e57ba5563708daca94dd84ad7112f,0x8b3e96f2b889fa771c53c981b40daf005f63f637f1869f707052d15a3dd97140,0x2170c741c41531aec20e7c107c24eecfdd15e69c9bb0a8dd37b1840b9e0b207b,0x19b47279256b2a23a1665c810c8d55a1758940ee09377d4f8d26497a3577dc83)) AS n_foreign_swap_logs,count_if(l.contract_address = 0x00000000000014aa86c5d3c41765bb24e11bd701 AND l.topic0 IS NULL AND bytearray_length(l.data) = 116) AS n_ekubo_swap_logs,count_if(l.topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef AND bytearray_substring(l.topic1, 13, 20) = tx.tx_from) > 0 AS sender_sent_erc20FROM tx JOIN ethereum.logs l ON l.tx_hash = tx.tx_hash AND l.block_number = tx.block_numberWHERE l.block_date >= date '{{start}}' AND l.block_date < date '{{end}}'GROUP BY 1, 2, 3, 4