Query editor
withraw_trades as (selectdate_trunc('minute', block_time) as block_time, casewhen tx_to = 0x7a250d5630b4cf539739df2c5dacb4c659f2488d then 'Uniswap V2: Router 2'when tx_to = 0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad then 'Uniswap: Universal Router'when tx_to = 0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45 then 'Uniswap V3: Router 2'when tx_to = 0x03f7724180aa6b939894b5ca4314783b0b36b329 then 'Shiba Inu: ShibaSwap'when tx_to = 0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f then 'SushiSwap: Router'else cast(tx_to as varchar)end as router, casewhen topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 then 'V2 Swap'when topic0 = 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67 then 'V3 Swap'else cast(topic0 as varchar)end as func, contract_address-- , substr(topic1, 13, 20) as sender-- , substr(topic2, 13, 20) as recipient, casewhen topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 then cast(bytearray_to_uint256(substr(data, 1 + 32 * 0, 32)) as int256) - cast(bytearray_to_uint256(substr(data, 1 + 32 * 2, 32)) as int256) -- amount0_in - amount0_outwhen topic0 = 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67 then bytearray_to_int256(substr(data, 1 + 32 * 0, 32)) -- amount0else nullend as raw_amount0, casewhen topic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 then cast(bytearray_to_uint256(substr(data, 1 + 32 * 1, 32)) as int256) - cast(bytearray_to_uint256(substr(data, 1 + 32 * 3, 32)) as int256) -- amount1_in - amount1_outwhen topic0 = 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67 then bytearray_to_int256(substr(data, 1 + 32 * 1, 32)) -- amount0else nullend as raw_amount1, tx_hashfrom ethereum.logswhere block_date >= date '2023-10-01'and topic0 in (0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822 -- Uniswap: V2 Swap, 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67 -- Uniswap: V3 Swap)and tx_from = 0xaf2358e98683265cbd3a48509123d390ddf54534order by block_time desclimit 1000), trades as (selectraw_trades.block_time, router, func, raw_trades.contract_address, if(t0.symbol is null, cast(token0 as varchar), t0.symbol) as token0, raw_amount0, if(t0.decimals is null, null, raw_amount0 / power(10, t0.decimals)) as amount0, if(t1.symbol is null, cast(token1 as varchar), t1.symbol) as token1, raw_amount1, if(t1.decimals is null, null, raw_amount1 / power(10, t1.decimals)) as amount1, tx_hashfrom raw_tradesleft join uniswap_ethereum.pools on raw_trades.contract_address = poolleft join tokens_ethereum.erc20 t0 on token0 = t0.contract_addressleft join tokens_ethereum.erc20 t1 on token1 = t1.contract_address)