Query editor
-- Query 1: Cumulative TVL for frxUSD PegKeeper Pools (USD-accurate, fast)-- Strategy:-- * pool_tvl = frxUSD_balance + paired_balance × paired_token_latest_price-- * For each pool, the "paired token" is the priced ERC-20 with the largest-- current USD value in the pool. This filters out spam-airdropped tokens-- that polluted prior runs (e.g. the $53B USDf number was driven by a-- non-paired token whose balance × fallback $1 dominated the sum).-- * Latest price (within the last 7 days) is applied uniformly to all-- historical days. Yield-bearing share tokens appreciate slowly (~5-15% APY),-- so this slightly overstates older days but is bounded and dramatically-- faster than per-day joins with forward-fill.---- If a pool's paired token isn't indexed by prices.usd_daily, paired_tvl shows-- 0 and `missing_paired_price = true` on the output. Add an explicit price-- override for that token if needed.WITH pool_addresses AS (SELECT 0x13e12BB0E6A2f1A3d6901a59a9d585e89A6243e1 AS pool_address, 'frxUSD/crvUSD' AS pool_nameUNION ALL SELECT 0x9A9e2e70919c75D80aAaA1D483c46CdBb8ac4d1b, 'frxUSD/msUSD'UNION ALL SELECT 0x20d4c49a873EaeFf76EfBD0cF19002F6E19EF52c, 'frxUSD/USDaf'UNION ALL SELECT 0x851907CAC684797eee43669798D78004e269Cb5E, 'frxUSD/fxUSD'UNION ALL SELECT 0x2eFC11c7Bb2E0FBdBa8A05a3712398860E6A8E53, 'frxUSD/USDfi'UNION ALL SELECT 0x2Cc565dDe7C078A8E477763a34C40e52b13e6396, 'frxUSD/YUSD'UNION ALL SELECT 0x98E9599dab3A936C35DE48E13E026Ef4eA20B5e6, 'frxUSD/USDf'UNION ALL SELECT 0xBf5047039F2980C21eB5692c790BAd8A9533b900, 'frxUSD/pmUSD'UNION ALL SELECT 0x68d03Ed49800e92D7Aa8aB171424007e55Fd1F49, 'frxUSD/OUSD'UNION ALL SELECT 0x3e823bd1015Ba1A12F2F8aFD631c822a1CBA0de7, 'frxUSD/iUSD'UNION ALL SELECT 0x421194e547eb49304B3e99ffD26b164f9832d395, 'frxUSD/reUSD'UNION ALL SELECT 0x917213760aF19E938E1C5cf4c6c3a963f6F32152, 'frxUSD/savUSD'UNION ALL SELECT 0xf76329c6dc10FdfbEe6CA520d0BF4d474E95E46E, 'frxUSD/avUSD'UNION ALL SELECT 0x6dD7522c83ecd5d67F8eaF11A973219C6A9f7493, 'frxUSD/tmvUSDC'UNION ALL SELECT 0x249839821B7B673bC68a6d9bC74811fa33A8a49f, 'frxUSD/dUSD'UNION ALL SELECT 0x8fc753f96752b35f64d1bae514e6cf8db0b9322e, 'frxUSD/srRoyUSDC'UNION ALL SELECT 0x17f9682c9cd1a448b31c0428f1d0783ed13a9fa3, 'frxUSD/alUSD'UNION ALL SELECT 0xefc056790bb19702b2164ec6ea6ba3ae01d81195, 'frxUSD/USG'UNION ALL SELECT 0xd50492de3541d75e61edc34d1aa79c7dc2d20da9, 'frxUSD/USP'UNION ALL SELECT 0x31d563e7d382cd934014bec8c6c931751e6b3a9a, 'frxUSD/ebUSD'UNION ALL SELECT 0x96bca2cea58a8e08e7da5c9d68b8acbb28419d1d, 'frxUSD/USPC'UNION ALL SELECT 0xcaf1969e9ba98c05113b75d8633a17196e2d02a5, 'frxUSD/sUSDat'UNION ALL SELECT 0x9d8afd5ce19a3b948049468188f1de13951a4383, 'frxUSD/sDOLA'UNION ALL SELECT 0x552827613fea5eada3871f83b2d407d50cb04116, 'frxUSD/evaUSDT'UNION ALL SELECT 0x01646f6fe0d75ced6e514fab0ea2f4ed5e1a5c9f, 'frxUSD/muBOND'UNION ALL SELECT 0x16a973f8e466f44e9ea67e7e2d3166bd460ea852, 'frxUSD/AZND'),frxusd_token AS (SELECT 0xCAcd6fd266aF91b8AeD52aCCc382b4e165586E29 AS token_address),-- ==================== TRANSFER AGGREGATION ====================-- Any ERC-20 (other than frxUSD) transferred in/out of any pool, daily, raw unitsnon_frxusd_changes AS (SELECTp.pool_name,t.contract_address AS token_address,DATE_TRUNC('day', t.evt_block_time) AS day,SUM(CASEWHEN t.to = p.pool_address THEN TRY_CAST(t.value AS DOUBLE)WHEN t."from" = p.pool_address THEN -TRY_CAST(t.value AS DOUBLE)ELSE 0