Query editor
-- ============================================================-- Suilend — Hero Counters (FIXED — uses correct Suilend event package)-- ============================================================-- Two data sources, both from Suilend's package 0xf95b06141...:-- 1) ReserveAssetDataEvent (USD pre-computed by Pyth) for protocol state-- 2) lending_market::* events for 14d activity (wallets, obligations, liquidations)-- ============================================================WITH-- TVL snapshot from latest ReserveAssetDataEvent per tokenraw_tvl AS (SELECTdate AS day,timestamp_ms,event_index,json_extract_scalar(event_json, '$.coin_type.name') AS token,try_cast(json_extract_scalar(event_json, '$.available_amount_usd_estimate.value') AS DOUBLE) / 1e18 AS available_usd,try_cast(json_extract_scalar(event_json, '$.supply_amount_usd_estimate.value') AS DOUBLE) / 1e18 AS supply_usd,try_cast(json_extract_scalar(event_json, '$.borrowed_amount_usd_estimate.value') AS DOUBLE) / 1e18 AS borrow_usdFROM sui.eventsWHERE date >= CURRENT_DATE - INTERVAL '2' DAYAND event_type = '0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::reserve::ReserveAssetDataEvent'AND json_extract_scalar(event_json, '$.coin_type.name') != '76cb819b01abed502bee8a702b4c2d547532c12f25001c9dea795a5e631c26f1::fud::FUD'),ranked_tvl AS (SELECT *,row_number() OVER (PARTITION BY day, token ORDER BY timestamp_ms DESC, event_index DESC) AS rnFROM raw_tvl),latest_tvl AS (SELECTSUM(supply_usd) AS total_supply_usd,SUM(borrow_usd) AS total_borrow_usd,SUM(available_usd) AS total_available_usd,COUNT(DISTINCT token) AS asset_countFROM ranked_tvlWHERE rn = 1 AND day = (SELECT MAX(day) FROM ranked_tvl)),latest_stable_supply AS (SELECT SUM(supply_usd) AS stable_supply_usdFROM ranked_tvlWHERE rn = 1 AND day = (SELECT MAX(day) FROM ranked_tvl)AND upper(split_part(token, '::', 3)) IN ('USDC','USDT','AUSD','BUCK','FDUSD','USDY','USDSUI','SUI_USDE','USDB','SEND','MUSD','UP')),-- Activity from Suilend's OWN lending_market events (was wrong before — was using Navi)activity AS (SELECTCOUNT(DISTINCT sender) AS unique_active_users_14d,COUNT(DISTINCT json_extract_scalar(event_json, '$.obligation_id')) AS unique_obligations_14d,SUM(CASE WHEN event_type LIKE '%::LiquidateEvent' THEN 1 ELSE 0 END) AS liquidations_14d,SUM(CASE WHEN event_type LIKE '%::ClaimRewardEvent' THEN 1 ELSE 0 END) AS reward_claims_14dFROM sui.eventsWHERE date >= CURRENT_DATE - INTERVAL '14' DAYAND event_type IN ('0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::lending_market::DepositEvent','0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf::lending_market::WithdrawEvent',