Query editor
-- TSI v2 | Coinbase B20 Chainlink Feed Observer-- Direct onchain observation from raw Base traces. Avoids decoded-table ABI coverage gaps.WITH assets(ticker,token_address,feed_address,declared_decimals) AS (VALUES('AAPL',0xb200000000000000000000c2e324d24d7eecd1fb,0x787f13dea48db0897cbcdd985de77809d837f988,8),('AMZN',0xb200000000000000000000d9192b6b456483c2e8,0x06a8e4b3abb3b7543d8396fb2b763d22820cb295,8),('COIN',0xb200000000000000000000c85a31389d71f3ecfb,0x408e44f504a7371a345f03a73ddc96a4b48e8aa7,8),('CRCL',0xb20000000000000000000019f6e7c675b73c2e4d,0x0231cf2635d1e17bb5c2462cc7504ba1fbd61f33,8),('GOOGL',0xb2000000000000000000002d0ba3164cc74f58b7,0x5bf49e0ffa937ce2fff033c739ad7c634c4d34f2,8),('INTC',0xb2000000000000000000004aff16039ba04bdfbc,0xab657c39bac0d5886250d70849e2e3e008f2eecb,8),('META',0xb2000000000000000000008bc8786b856e61707c,0x6526ae6797a76123638b863aee4dd27ba4e4b27d,8),('MSFT',0xb200000000000000000000ab99cfa739e253872b,0xeb10a6c9aa7e537aed766c08c35dae35b321b18c,8),('MSTR',0xb2000000000000000000004884b426556b92883d,0xb3ce282cd188b35da0e38d8bc7d58e33173d202a,8),('NVDA',0xb20000000000000000000078ee7ce2fe4908108c,0x04689a41629776563e6822f76f2e57d148d28513,8),('SNDK',0xb200000000000000000000397293cb8cda9a10c5,0x388b0dc46c0fb05a74bee0994fa5b02c6fcca2ea,8),('SPCX',0xb2000000000000000000007b9fcbd005511acbd5,0x6a634b235903c4ad6376892180d6ff8612e3fa68,8),('TSLA',0xb2000000000000000000001e800a7f5189430cd0,0xfaf869185383a24f8cb00e27bda6b63b9905dcb4,8)),raw_round_calls AS (SELECT a.ticker,a.token_address,a.feed_address,t.block_time call_time,t.block_number,t.tx_hash,t.output,row_number() over(partition by a.feed_address order by t.block_number desc,t.tx_index desc,t.trace_address desc) rn,count(*) over(partition by a.feed_address) calls_4d,count_if(t.block_time>=current_timestamp-INTERVAL '24' HOUR) over(partition by a.feed_address) calls_24h,count_if(t.block_time>=current_timestamp-INTERVAL '7' DAY) over(partition by a.feed_address) calls_7dFROM base.traces t JOIN assets a ON t.to=a.feed_addressWHERE t.block_date>=CURRENT_DATE-INTERVAL '4' DAYAND t.type='call' AND t.successAND bytearray_substring(t.input,1,4)=0xfeaf968cAND length(t.output)>=160),raw_decimals AS (SELECT a.feed_address,CAST(varbinary_to_uint256(bytearray_substring(t.output,1,32)) AS INTEGER) decimals,row_number() over(partition by a.feed_address order by t.block_number desc,t.tx_index desc,t.trace_address desc) rnFROM base.traces t JOIN assets a ON t.to=a.feed_addressWHERE t.block_date>=CURRENT_DATE-INTERVAL '4' DAYAND t.type='call' AND t.successAND bytearray_substring(t.input,1,4)=0x313ce567AND length(t.output)>=32),decoded AS (SELECT r.*,COALESCE(d.decimals,8) decimals,varbinary_to_uint256(bytearray_substring(r.output,1,32)) round_id,varbinary_to_int256(bytearray_substring(r.output,33,32)) answer_raw,varbinary_to_uint256(bytearray_substring(r.output,65,32)) started_at,varbinary_to_uint256(bytearray_substring(r.output,97,32)) updated_at,varbinary_to_uint256(bytearray_substring(r.output,129,32)) answered_in_roundFROM raw_round_calls r LEFT JOIN raw_decimals d ON d.feed_address=r.feed_address AND d.rn=1WHERE r.rn=1),market_prices AS (SELECT contract_address,price,timestamp,sourceFROM prices.latestWHERE blockchain='base' AND contract_address IN (SELECT token_address FROM assets))SELECT CURRENT_DATE snapshot_date,a.ticker,a.token_address,a.feed_address,COALESCE(d.decimals,a.declared_decimals) decimals,CASE WHEN d.answer_raw IS NOT NULLTHEN CAST(d.answer_raw AS DOUBLE)/power(10,COALESCE(d.decimals,a.declared_decimals)) END chainlink_total_return_price,CASE WHEN d.updated_at IS NOT NULL THEN from_unixtime(CAST(d.updated_at AS BIGINT)) END feed_updated_at,d.call_time latest_observed_call_time,