Query editor
WITH daily_activity AS (-- Deposits (USR transfers to factory)SELECTDATE_TRUNC('day', evt_block_time) AS date,"from" AS user_address,value / 1e18 AS amount,evt_tx_hash AS tx_hashFROM erc20_ethereum.evt_TransferWHERE contract_address = 0x66a1e37c9b0eaddca17d3662d6c05f4decf3e110 -- USR tokenAND evt_tx_to = 0x3e9f065cdf0a0c597c5bb5719feab059c23f359d -- factory contractAND "from" != 0x0000000000000000000000000000000000000000AND "to" != 0x6c8984bc7dbbedaf4f6b2fd766f16ebb7d10aab4AND evt_block_time >= TIMESTAMP '2025-11-25'UNION ALL-- Withdrawals (principal only, excluding yield)SELECTDATE_TRUNC('day', block_time) AS date,tx_from AS user_address,-1 * (bytearray_to_uint256(bytearray_substring(data, 1, 32)) - ABS(bytearray_to_int256(bytearray_substring(data, 65, 32)))) / 1e18 AS amount,tx_hashFROM ethereum.logsWHERE topic0 = 0xaaa8a19747d8ce2fca454fcab519969036adf4ab5a98433ba0a09680d3759ad2 -- P2pYieldProxy__WithdrawnAND block_time >= TIMESTAMP '2025-11-25'),daily_aggregates AS (SELECTdate,SUM(amount) AS net_flow,COUNT(DISTINCT CASE WHEN amount > 0 THEN user_address END) AS new_depositors,COUNT(DISTINCT CASE WHEN amount < 0 THEN user_address END) AS withdrawers,COUNT(DISTINCT tx_hash) AS unique_txsFROM daily_activityGROUP BY date),date_series AS (SELECT timestamp AS dateFROM utils.daysWHERE timestamp >= TIMESTAMP '2025-11-25'AND timestamp <= CURRENT_DATE)SELECTds.date,COALESCE(SUM(da.new_depositors) OVER (ORDER BY ds.date), 0) AS cumulative_depositors,COALESCE(SUM(da.withdrawers) OVER (ORDER BY ds.date), 0) AS cumulative_withdrawers,COALESCE(SUM(da.new_depositors) OVER (ORDER BY ds.date), 0) - COALESCE(SUM(da.withdrawers) OVER (ORDER BY ds.date), 0) AS active_depositors,COALESCE(da.unique_txs, 0) AS daily_unique_transactions,COALESCE(SUM(da.net_flow) OVER (ORDER BY ds.date), 0) AS tvl_cumulativeFROM date_series dsLEFT JOIN daily_aggregates da ON ds.date = da.dateORDER BY ds.date DESC