Query editor
-- Kasu Base (USDC, 6dp). Dune has no decoded tables for Kasu, so every amount is-- sliced out of the raw log `data` by hand. Each series is reconciled against the-- Kasu subgraph:-- Total Lent = SUM(DepositAccepted.amount) == totalDepositsAccepted-- Total Active Lending = pool-token mints - burns == LendingPool.balance-- Lender Interest = SUM(InterestApplied.interestAmount) == totalUserInterestAmount-- Fees accrued = SUM(FeesOwedIncreased.amount) == totalFeesAmount-- Revenue realised = SUM(PaidFees + PaidFeesFromAvailableFunds)WITH pools AS (SELECT pool FROM (VALUES(0x03f93c8caa9a82e000d35673ba34a4c0e6e117a2), (0x2bf0c43659c2a9f2ca15a9c335a8f2689dff7ab2),(0x54a98e1baed45854789b0448ed1277997d64fffe), (0x9185162fb82f6b4fd469b5127fe3874dfa74f652),(0xa30d35aa4ebb885c9c7bb9de766266cd6a221ebe), (0xb6deab2f712efc9df8c1e949b194bee12f9c04fe),(0xc347a9e4aec8c8d11a149d2907deb2bf23b81c6f), (0xc987350716fe4a7d674c3591c391d29eba26b8ce),(0xe621ec2a0de3c9eab96e088256b60c59fff87607)) AS t(pool)),raw AS (SELECT l.block_date AS day, l.topic0, l.topic1, l.topic2, l.dataFROM base.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,-- LossReported. Has never fired on Base; kept so a first loss surfaces.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,