Query editor
-- ERC20/WETH multi-source decodingWITH swap_event AS (SELECTDATE_TRUNC('minute', block_time) AS time_swap,contract_address,bytearray_to_uint256(bytearray_substring(data, 1, 32)) / 1e18 AS amount0_in,bytearray_to_uint256(bytearray_substring(data, 33, 32)) / 1e18 AS amount1_in,bytearray_to_uint256(bytearray_substring(data, 65, 32)) / 1e18 AS amount0_out,bytearray_to_uint256(bytearray_substring(data, 97, 32)) / 1e18 AS amount1_outFROMethereum.logsWHEREtopic0 = 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822ANDcontract_address = 0x69C7bd26512f52bF6F76faB834140D13Dda673CaANDblock_time > CURRENT_DATE - INTERVAL '7' day),price AS (SELECT"minute",price AS quote_token_price_usdFROMprices.usdWHEREblockchain = 'ethereum'ANDcontract_address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2AND"minute" > CURRENT_DATE - INTERVAL '7' day),pool_metadata AS (SELECTCAST(json_extract_scalar(response,'$.pairs[0].priceUsd') AS DOUBLE) AS base_token_price_usd,json_extract_scalar(response,'$.pairs[0].pairAddress') AS pool_addressFROM (SELECT json_parse(http_get('https://api.dexscreener.com/latest/dex/pairs/ethereum/0x69C7bd26512f52bF6F76faB834140D13Dda673Ca')) AS response)),pre_agg AS (SELECTDATE_TRUNC('hour', s.time_swap) AS hours,s.amount0_in,s.amount0_out,s.amount1_in,s.amount1_out,a.quote_token_price_usd,p.base_token_price_usd,CASEWHEN s.amount0_in > s.amount0_out THEN 'sold_token0'WHEN s.amount0_out > s.amount0_in THEN 'bought_token0'END AS trade_direction,