Query editor
-- bankr-launch-v3-elysium-daily [materialized source]-- Elysium (99901) is not on Dune: logs come from the public RPC via LiveFetch. Each call is tried three times-- (try() turns a failed call into NULL); an RPC error after that aborts the run (the guard casts the error-- text to INTEGER) so the matview never stores a partial day. Swaps come in 500k-block chunks (LiveFetch caps-- each response at 4 MiB / 5 s).WITH req AS (SELECT 'https://rpc.elysium.kinetiq.xyz' AS url,ARRAY['Content-Type: application/json'] AS hdr,'{"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{"fromBlock":"0x21a841","toBlock":"latest","address":"0xD8bB9413fFABff303A8f85C42E00ce51cB15bA50","topics":["0xe4c995d391c41bdf7603d29153dab3f7482e221dd45736de2d236e5d5f8594eb"]}]}' AS launches_req,'{"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{"fromBlock":"0x21a841","toBlock":"latest","address":"0x7C41b53Cead27F0239D04c57e0a12c52939b6D33","topics":["0x593f66b1a67dcf30d5f9517cc0db3a3559a8013e777b376cdfbf968f14e0faeb"]}]}' AS splits_req,'{"jsonrpc":"2.0","id":1,"method":"eth_blockNumber","params":[]}' AS head_req),rpc_launches AS (SELECT COALESCE(try(http_post(url, launches_req, hdr)),try(http_post(url, replace(launches_req, '"id":1', '"id":2'), hdr)),http_post(url, replace(launches_req, '"id":1', '"id":3'), hdr)) AS bodyFROM req),launch_logs AS (SELECT xFROM (SELECT json_parse(body) AS j,CASE WHEN json_extract(json_parse(body), '$.result') IS NULLTHEN CAST('Elysium RPC error (launches): ' || substr(body, 1, 200) AS INTEGER) END AS guardFROM rpc_launches) rCROSS JOIN UNNEST(CAST(json_extract(r.j, '$.result') AS ARRAY(JSON))) AS t(x)WHERE r.guard IS NULL),launches AS (SELECT from_unixtime(from_base(substr(json_extract_scalar(x, '$.blockTimestamp'), 3), 16)) AS block_time,from_hex(substr(json_extract_scalar(x, '$.topics[1]'), 27)) AS token,from_hex(substr(json_extract_scalar(x, '$.topics[2]'), 27)) AS pool,'0x' || substr(json_extract_scalar(x, '$.topics[2]'), 27) AS pool_hex,from_hex(substr(json_extract_scalar(x, '$.data'), 27, 40)) AS quoteFROM launch_logs),quotes (quote, symbol, decimals) AS (VALUES (0xba876237b0f021a6c6d852d6c26e107997cc5e81, 'WHYPE', 18)),head AS (SELECT from_base(substr(json_extract_scalar(json_parse(COALESCE(try(http_post(url, head_req, hdr)),try(http_post(url, replace(head_req, '"id":1', '"id":2'), hdr)),http_post(url, replace(head_req, '"id":1', '"id":3'), hdr))), '$.result'), 3), 16) AS latestFROM req),pool_list AS (SELECT '[' || array_join(array_agg('"' || pool_hex || '"'), ',') || ']' AS addrs FROM launches),chunks AS (SELECT s AS from_block, LEAST(s + 499999, h.latest) AS to_blockFROM head hCROSS JOIN UNNEST(sequence(CAST(2205761 AS BIGINT), h.latest, CAST(500000 AS BIGINT))) AS t(s)),swap_reqs AS (SELECT c.from_block, r.url, r.hdr,'{"jsonrpc":"2.0","id":1,"method":"eth_getLogs","params":[{"fromBlock":"0x' || lower(to_base(c.from_block, 16))|| '","toBlock":"0x' || lower(to_base(c.to_block, 16)) || '","address":' || p.addrs|| ',"topics":["0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67"]}]}' AS body_reqFROM chunks c CROSS JOIN pool_list p CROSS JOIN req r),