Query editor
WITH scroll_croc_traces AS (SELECT534352 as chain_id, t.tx_hash as tx_hash, t.tx_index,bytearray_substring(t.input, 1, 4) AS method_id,t.tx_index as t_tx_index, t.block_number as t_block_number, t.block_time,outer_call.to as tx_to,try(map(ARRAY[0x3d719cd9, 0xa15112f9, 0x13fd34f4, 0x08719070, 0x90b33ce5, 0x7c6dfe3d, 0x7b370fc2, 0x2370632b, 0x2ee11587],ARRAY['swap', 'userCmd', 'protocolCmd', 'userCmdRelayer', 'userCmdRouter', 'micro_burnConcLp', 'micro_swap', 'micro_mintConcLp', 'micro_mintAmbLp'])[bytearray_substring(t.input, 1, 4)]) as method,CASE bytearray_substring(t.input, 1, 4)WHEN 0xa15112f9 THEN bytearray_to_integer(bytearray_substring(t.input, 4 + 29, 4))WHEN 0x13fd34f4 THEN bytearray_to_integer(bytearray_substring(t.input, 4 + 29, 4))END as callpath_idx,CASE bytearray_substring(t.input, 1, 4)WHEN 0xa15112f9 THEN bytearray_to_integer(bytearray_substring(t.input, 4 + 96 + 29, 4))WHEN 0x13fd34f4 THEN bytearray_to_integer(bytearray_substring(t.input, 4 + 128 + 29, 4))END as cmd_idx,t.input, t.outputFROM scroll.traces as tINNER JOIN scroll.traces as outer_call ON outer_call.block_number = t.block_number AND outer_call.tx_index = t.tx_index AND outer_call.trace_address = ARRAY[]WHEREt.block_number >= 267408 AND (t.to = 0xaaaaaaaacb71bf2c8cae522ea5fa455571a74106 OR t.to = 0x646929453e753565467f330110850885ead93fa9 OR t.to = 0x418c68ce5b73783abe178db12dfee9375d965dbb) AND t.success), croc_swap_traces AS (SELECT *FROM scroll_croc_tracesWHERE method = 'swap' OR method = 'micro_swap' OR (method = 'userCmd' and callpath_idx = 1)), pools AS (SELECTCASE WHEN method = 'swap' THEN bytearray_substring(input, 4 + 12 + 1, 20) WHEN (method = 'userCmd' and callpath_idx = 1) THEN bytearray_substring(input, 4 + 96 + 12 + 1, 20) END as base,CASE WHEN method = 'swap' THEN bytearray_substring(input, 4 + 12 + 33, 20) WHEN (method = 'userCmd' and callpath_idx = 1) THEN bytearray_substring(input, 4 + 96 + 12 + 33, 20) END as quote,CASE WHEN method = 'swap' THEN bytearray_substring(input, 4 + 28 + 65, 4) WHEN (method = 'userCmd' and callpath_idx = 1) THEN bytearray_substring(input, 4 + 96 + 28 + 65, 4) END as pool_idxFROM croc_swap_tracesWHERE method = 'swap' OR (method = 'userCmd' and callpath_idx = 1)GROUP BYCASE WHEN method = 'swap' THEN bytearray_substring(input, 4 + 12 + 1, 20) WHEN (method = 'userCmd' and callpath_idx = 1) THEN bytearray_substring(input, 4 + 96 + 12 + 1, 20) END,CASE WHEN method = 'swap' THEN bytearray_substring(input, 4 + 12 + 33, 20) WHEN (method = 'userCmd' and callpath_idx = 1) THEN bytearray_substring(input, 4 + 96 + 12 + 33, 20) END,CASE WHEN method = 'swap' THEN bytearray_substring(input, 4 + 28 + 65, 4) WHEN (method = 'userCmd' and callpath_idx = 1) THEN bytearray_substring(input, 4 + 96 + 28 + 65, 4) END), pool_hashes as (SELECT keccak(bytearray_concat(bytearray_concat(bytearray_concat(0x000000000000000000000000, base), bytearray_concat(0x000000000000000000000000, quote)), bytearray_concat(0x00000000000000000000000000000000000000000000000000000000, pool_idx))) as pool_hash,map_from_entries(ARRAY[('base', base),('quote', quote),('pool_idx', pool_idx)]) as poolFROM pools), scroll_tokens AS (-- Generated list of all tokens that occur in Ambient pools as of 2024-08-16. There's probably an easier and better way to do this.SELECT 0x0000000000000000000000000000000000000000 as croc_addr, 0x5300000000000000000000000000000000000004 as token_addr, 'ETH' as symbol, 18 as decimals UNION ALLSELECT 0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051 as croc_addr, 0xedeabc3a1e7d21fe835ffa6f83a710c70bb1a051 as token_addr, 'LUSD' as symbol, 18 as decimals UNION ALLSELECT 0xc4d46e8402f476f269c379677c99f18e22ea030e as croc_addr, 0xc4d46e8402f476f269c379677c99f18e22ea030e as token_addr, 'PufETH' as symbol, 18 as decimals UNION ALLSELECT 0xcef2b779cabebfebe1a919a7a3f650648700e514 as croc_addr, 0xcef2b779cabebfebe1a919a7a3f650648700e514 as token_addr, 'MPEPE' as symbol, 18 as decimals UNION ALLSELECT 0xc7ad21d69e1f63578261a10c9d1a0637e82d0512 as croc_addr, 0xc7ad21d69e1f63578261a10c9d1a0637e82d0512 as token_addr, 'google' as symbol, 18 as decimals UNION ALLSELECT 0xb830b391497d9c79eb5ca88ea4e34e15e8dc35f0 as croc_addr, 0xb830b391497d9c79eb5ca88ea4e34e15e8dc35f0 as token_addr, 'Blobs Token' as symbol, 18 as decimals UNION ALLSELECT 0x88448c2970bb3f7303042e6fbf73bc7f26696052 as croc_addr, 0x88448c2970bb3f7303042e6fbf73bc7f26696052 as token_addr, 'DAI' as symbol, 18 as decimals UNION ALLSELECT 0xe4f76b457e248839d80ba92cbab428802c85f3c3 as croc_addr, 0xe4f76b457e248839d80ba92cbab428802c85f3c3 as token_addr, 'DOG' as symbol, 18 as decimals UNION ALLSELECT 0x3b97ccc0c8c5e10ac3e7f1594b55b6239a493eea as croc_addr, 0x3b97ccc0c8c5e10ac3e7f1594b55b6239a493eea as token_addr, 'stoneQUEEN' as symbol, 18 as decimals UNION ALLSELECT 0x95a52ec1d60e74cd3eb002fe54a2c74b185a4c16 as croc_addr, 0x95a52ec1d60e74cd3eb002fe54a2c74b185a4c16 as token_addr, 'SKY' as symbol, 18 as decimals UNION ALLSELECT 0xe795f59d3556285454bd00cabc35682dc8455fc2 as croc_addr, 0xe795f59d3556285454bd00cabc35682dc8455fc2 as token_addr, 'SOI' as symbol, 18 as decimals UNION ALLSELECT 0x65421ba909200b81640d98b979d07487c9781b66 as croc_addr, 0x65421ba909200b81640d98b979d07487c9781b66 as token_addr, 'rsETH' as symbol, 18 as decimals UNION ALL