Query editor
-- Accurate deposit duration analysis showing individual deposit cycles-- Each deposit cycle (from positive balance to zero balance) gets its own rowWITH target_contracts AS (SELECT contract_addrFROM (VALUES(from_hex('594380c06552a4136e2601f89e50b3b9ad17bd4d')),(from_hex('544f45485418341c1a2b3a44404f12302277fffc')),(from_hex('9c0823d3a1172f9ddf672d438dec79c39a64f448')),(from_hex('b09a50acfff7d12b7a3def3d1027bc149bad1c')),(from_hex('52cb8a621610cc3ccf498a1981a8ae7ad6b8ab2a')),(from_hex('940750a267c64f3bbce31b948b67cd168f0843fa')),(from_hex('21dbba985eea6ba7f27534a72ccb292eba1d2c7c')),(from_hex('971e5b5d4baa5607863f3748febf287c7bf82618')),(from_hex('0c969cec0729487d264716e55f232b404299032c')),(from_hex('e39b5f5638a209c1a6b6cdffe5d37f7ac99fcc84')),(from_hex('19d0d8e6294b7a04a2733fe433444704b791939a')),(from_hex('bdea8e677f9f7c294a4556005c640ee505be6925')),(from_hex('03bf48b8a1b37fbead1ecabcf15b98b924ffa5ac')),(from_hex('5198cb44d7b2e993ebdda9cad3b9a0eaa32769d2')),(from_hex('475d3eb031d250070b63fa145f0fcfc5d97c304a')),(from_hex('422f5accc812c396600010f224b320a743695f85')),(from_hex('b26ff591f44b04e78de18f43b46f8b70c6676984')),(from_hex('38b86004842d3fa4596f0b7a0b53de90745ab654')),(from_hex('c329400492c6ff2438472d4651ad17389fcb843a'))) AS t(contract_addr)),-- Get all transfers (deposits and withdrawals)all_transfers AS (-- Deposits (transfers TO the contracts)SELECTt."from" AS user_address,t.contract_address AS token_address,t.evt_block_time,CAST(t.value AS DOUBLE) AS amount,'deposit' AS transfer_typeFROM erc20_ethereum.evt_transfer tINNER JOIN target_contracts c ON t."to" = c.contract_addrWHERE t."from" != from_hex('0000000000000000000000000000000000000000')AND t.evt_block_time <= TIMESTAMP '2025-01-26'UNION ALL-- Withdrawals (transfers FROM the contracts)SELECTt."to" AS user_address,t.contract_address AS token_address,t.evt_block_time,-CAST(t.value AS DOUBLE) AS amount, -- Negative for withdrawals'withdrawal' AS transfer_typeFROM erc20_ethereum.evt_transfer tINNER JOIN target_contracts c ON t."from" = c.contract_addrWHERE t."to" != from_hex('0000000000000000000000000000000000000000')AND t.evt_block_time <= TIMESTAMP '2025-01-26'),-- Calculate running balance firstrunning_balances_step1 AS (SELECT