Query editor
WITH candidates(project, chain, rpc, comptroller, market, cf_pct) AS (VALUES('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x103f2ca2148b863942397dbc50a425cc4f4e9a27',0.85),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x42b458056f887fd665ed6f160a59afe932e1f559',0.85),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x607312a5c671d0c511998171e634de32156e69d0',0.85),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x9a9c7c065efcd4a8ffbf3d97882bbcaed4eb2910',0.85),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0xfcd8570ad81e6c77b8d252bebeba62ed980bd64d',0.85),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x090a00a2de0ea83def700b5e216f87a5d4f394fe',0.75),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x243e33aa7f6787154a8e59d3c27a66db3f8818ee',0.75),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0x89db3b59381bc06fe9bf74532afd777e5f78ef02',0.75),('hundred_finance','optimism','https://optimism-rpc.publicnode.com','0x0f390559f258eb8591c8e31cf0905e97cf36ace2','0xe8f12f5492ec28609d2932519456b7436d6c93bd',0.75),('unfederalreserve_v1','ethereum','https://ethereum-rpc.publicnode.com','0x3105d328c66d8d55092358cf595d54608178e9b5','0xfacece87e14b50eafc85c44c01702f5f485ca460',0.80)),sel AS (SELECTconcat('0x', lower(substr(to_hex(keccak(to_utf8('oracle()'))),1,8))) AS oracle_sel,concat('0x', lower(substr(to_hex(keccak(to_utf8('getUnderlyingPrice(address)'))),1,8))) AS price_sel,concat('0x', lower(substr(to_hex(keccak(to_utf8('supplyCaps(address)'))),1,8))) AS supply_caps_sel),base AS (SELECT c.*,concat('0x', substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', comptroller, '","data":"', (SELECT oracle_sel FROM sel), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),27,40)) AS oracle,json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', market, '","data":"0x6f307dc3"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result') AS underlying_hex,bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', market, '","data":"0x18160ddd"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64))) AS total_supply_raw,bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', market, '","data":"0x3b1d21a2"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64))) AS cash_raw,bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', market, '","data":"0x47bd3718"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64))) AS borrows_raw,bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', market, '","data":"0x8f840ddd"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64))) AS reserves_raw,bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', market, '","data":"0x182df0f5"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64))) AS exchange_rate_rawFROM candidates c),ud AS (SELECT b.*,CASE WHEN underlying_hex IS NOT NULL AND length(underlying_hex) >= 66 THEN concat('0x', substr(underlying_hex,27,40)) ELSE '0x0000000000000000000000000000000000000000' END AS underlyingFROM base b),dec AS (SELECT u.*,CASE WHEN underlying = '0x0000000000000000000000000000000000000000' THEN UINT256 '18'ELSE try(bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', underlying, '","data":"0x313ce567"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64)))) END AS underlying_decimals,try(bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', oracle, '","data":"', (SELECT price_sel FROM sel), lpad(substr(market,3),64,'0'), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64)))) AS price_raw,try(bytearray_to_uint256(from_hex(substr(json_extract_scalar(json_parse(http_post(rpc, concat('{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"', comptroller, '","data":"', (SELECT supply_caps_sel FROM sel), lpad(substr(market,3),64,'0'), '"},"latest"]}'), ARRAY['Content-Type: application/json'])), '$.result'),3,64)))) AS supply_cap_rawFROM ud u),calc AS (SELECT *,CAST(total_supply_raw AS DOUBLE)/1e8 AS ctoken_supply,CAST(cash_raw AS DOUBLE)/pow(10, CAST(underlying_decimals AS DOUBLE)) AS cash_underlying,CAST((cash_raw + borrows_raw - reserves_raw) AS DOUBLE)/pow(10, CAST(underlying_decimals AS DOUBLE)) AS supplied_underlying,CAST(exchange_rate_raw AS DOUBLE) AS er_raw_d,CAST(cash_raw AS DOUBLE) * CAST(price_raw AS DOUBLE) / 1e36 AS cash_usd_est,CAST((cash_raw + borrows_raw - reserves_raw) AS DOUBLE) * CAST(price_raw AS DOUBLE) / 1e36 AS supplied_usd_estFROM dec)SELECT project, chain, market, underlying, underlying_decimals, cf_pct,ctoken_supply, cash_underlying, supplied_underlying, cash_usd_est, supplied_usd_est,exchange_rate_raw, price_raw, supply_cap_raw,CASEWHEN ctoken_supply < 100 AND cf_pct >= 0.5 THEN 'HIGH_LOW_SUPPLY'WHEN ctoken_supply < 10000 AND cf_pct >= 0.5 THEN 'MEDIUM_LOW_SUPPLY'ELSE 'LOW_SUPPLY_NOT_LOW'