Query editor
WITH markets AS (SELECT project, chain, market, symbol, cash_usd, oracle_price_rawFROM query_7410644WHERE project IN ('wepiggy','aquariusloan')),surface AS (SELECT DISTINCT a.project, a.chain,CASE a.chain WHEN 'optimism' THEN 'https://optimism-rpc.publicnode.com' WHEN 'arbitrum' THEN 'https://arbitrum-one-rpc.publicnode.com' END AS rpc,a.oracleFROM query_7410674 aWHERE a.project IN ('wepiggy','aquariusloan')),sel AS (SELECTconcat('0x', substr(to_hex(keccak(to_utf8('owner()'))),1,8)) AS owner_sel,concat('0x', substr(to_hex(keccak(to_utf8('oracleLength(address)'))),1,8)) AS oracle_len_sel,concat('0x', substr(to_hex(keccak(to_utf8('oracles(address,uint256)'))),1,8)) AS oracles_sel,concat('0x', substr(to_hex(keccak(to_utf8('getOracleSourcePrice(address,uint256)'))),1,8)) AS source_price_sel),idx AS (SELECT * FROM (VALUES (0),(1),(2)) AS t(source_index)),owner_calls AS (SELECT s.*,json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', oracle, '","data":"', (SELECT owner_sel FROM sel), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result') AS owner_hexFROM surface s),len_calls AS (SELECT m.project, m.chain, s.rpc, s.oracle, m.market, m.symbol, m.cash_usd, m.oracle_price_raw,json_extract_scalar(json_parse(http_post(s.rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', s.oracle, '","data":"', (SELECT oracle_len_sel FROM sel), lpad(substr(m.market,3),64,'0'), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result') AS oracle_len_hexFROM markets m JOIN surface s USING(project,chain)),src_calls AS (SELECT l.*, i.source_index,json_extract_scalar(json_parse(http_post(l.rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', l.oracle, '","data":"', (SELECT oracles_sel FROM sel), lpad(substr(l.market,3),64,'0'), lpad(to_hex(i.source_index),64,'0'), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result') AS oracle_source_hex,json_extract_scalar(json_parse(http_post(l.rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', l.oracle, '","data":"', (SELECT source_price_sel FROM sel), lpad(substr(l.market,3),64,'0'), lpad(to_hex(i.source_index),64,'0'), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result') AS source_price_hexFROM len_calls l CROSS JOIN idx i),decoded AS (SELECT sc.*,try(CAST(bytearray_to_uint256(from_hex(substr(oracle_len_hex,3,64))) AS INTEGER)) AS oracle_len,CASE WHEN oracle_source_hex IS NOT NULL AND length(oracle_source_hex) >= 194 THEN concat('0x', substr(oracle_source_hex,27,40)) END AS source,try(CAST(bytearray_to_uint256(from_hex(substr(oracle_source_hex,67,64))) AS INTEGER)) AS source_type,try(CAST(bytearray_to_uint256(from_hex(substr(oracle_source_hex,131,64))) AS INTEGER)) AS source_available,try(CAST(bytearray_to_uint256(from_hex(substr(source_price_hex,3,64))) AS DOUBLE)) AS source_price_rawFROM src_calls sc),owners AS (SELECT project, chain, oracle,CASE WHEN owner_hex IS NOT NULL AND length(owner_hex)>=66 THEN concat('0x', substr(owner_hex,27,40)) END AS oracle_ownerFROM owner_calls)SELECT d.project, d.chain, d.oracle, o.oracle_owner, d.market, d.symbol, d.cash_usd, d.oracle_price_raw, d.oracle_len,d.source_index, d.source, d.source_type, d.source_available, d.source_price_raw,CASEWHEN d.oracle_len IS NULL THEN 'ABI_NOT_COMPATIBLE_OR_REVERT'WHEN d.source_index >= d.oracle_len THEN 'NO_SOURCE_AT_INDEX'WHEN d.source_available = 0 THEN 'SOURCE_DISABLED'WHEN d.source IS NULL THEN 'SOURCE_NULL_OR_PARSE_FAIL'ELSE 'SOURCE_CONFIGURED'END AS source_statusFROM decoded d