Query editor
-- Kasu Plume (pUSD). RETIRED: wound down and fully drained, so every series is-- frozen. Same contract shape as Base, so the same event signatures apply.WITH pools AS (SELECT pool FROM (VALUES(0xb47ee8770615e28dddbcd3fc1bcaf11f2c1e732a), -- Professional Fee Funding - A(0xb742668acced969b3ce64b4469e17f74a3e1d402), -- Taxation Funding - Diversifi(0xf5c8e1e658855e116c656b1790ef2b5951679764) -- Whole Ledger Funding) AS t(pool)),raw AS (SELECT l.block_date AS day, l.topic0, l.topic1, l.topic2, l.dataFROM plume.logs lJOIN pools p ON p.pool = l.contract_addressWHERE l.block_date >= DATE '2024-06-01'),daily AS (SELECT day,sum(CASE WHEN topic0 = 0x1f4980ade8ce51601be5a49a7c6e01b978d7502d304754d04b94c7a27c7be345THEN CAST(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS double) / 1e6 ELSE 0 END)AS deposits,sum(CASE WHEN topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efAND topic1 = 0x0000000000000000000000000000000000000000000000000000000000000000THEN CAST(bytearray_to_uint256(data) AS double) / 1e6WHEN topic0 = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efAND topic2 = 0x0000000000000000000000000000000000000000000000000000000000000000THEN -CAST(bytearray_to_uint256(data) AS double) / 1e6 ELSE 0 END)AS supply_delta,sum(CASE WHEN topic0 = 0xac35d60a678a4c2d8af0e4d7d40d7cc0f08640ae39013746b6ab334d74e4fd30THEN CAST(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS double) / 1e6 ELSE 0 END)AS interest,sum(CASE WHEN topic0 = 0xfed1651c705cdb5f52fcff6d7d7c0e20f8be41cf6a80d500b7b35ae88def1d87THEN CAST(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS double) / 1e6 ELSE 0 END)AS fees_accrued,sum(CASE WHEN topic0 IN (0xa635f5d0bd5f6b58372d0c962ea8574547bab4a3510296ef1d4b7e2fae5d70c9,0x21bdcde74ba233ab4096b4b85f1a8197622687a530ab445caaa97f77a5058ee3)THEN CAST(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS double) / 1e6 ELSE 0 END)AS fees_paid,sum(CASE WHEN topic0 = 0x3743c9e9a14de8dfa6e52fac936fe2cbf23e8e43d0d4c46ef57bcff3b377967eTHEN CAST(bytearray_to_uint256(bytearray_substring(data, 1, 32)) AS double) / 1e6 ELSE 0 END)AS lossesFROM raw GROUP BY day),cal AS (SELECT d AS day FROM unnest(sequence(DATE '2024-06-01', current_date, INTERVAL '1' DAY)) AS t(d))SELECTcal.day,sum(coalesce(daily.deposits, 0)) OVER (ORDER BY cal.day) AS total_lent,sum(coalesce(daily.supply_delta, 0)) OVER (ORDER BY cal.day) AS total_active_lending,sum(coalesce(daily.interest, 0)) OVER (ORDER BY cal.day) AS lender_interest_earned,sum(coalesce(daily.fees_accrued, 0)) OVER (ORDER BY cal.day) AS fees_cumulative,sum(coalesce(daily.fees_paid, 0)) OVER (ORDER BY cal.day) AS revenue_cumulative,sum(coalesce(daily.losses, 0)) OVER (ORDER BY cal.day) AS losses_cumulativeFROM calLEFT JOIN daily ON daily.day = cal.dayORDER BY cal.day DESC