hessAverage Days of Holding Position
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
›
⌄
with deposit as ( select date(block_timestamp) as deposit_date,'Deposit' as type,depositor_address, count(DISTINCT(tx_hash)) as tx,
count(DISTINCT(depositor_address)) as users , sum(SUPPLIED_USD) as volume,
avg(SUPPLIED_USD) as avg_volume, max(SUPPLIED_USD) as max_volume, median(SUPPLIED_USD) as median_volume
from ethereum.aave.ez_deposits
where block_timestamp::date >= current_date - {{N_Days}}
and symbol is not null
and symbol = 'AAVE'
group by 1,2,3)
,
withdraw as ( select date(block_timestamp) as withdraw_date, 'Withdraw' as type,depositor_address, count(DISTINCT(tx_hash)) as tx,
count(DISTINCT(depositor_address)) as users , sum(WITHDRAWN_USD) as volume,
avg(WITHDRAWN_USD) as avg_volume, max(WITHDRAWN_USD) as max_volume, median(WITHDRAWN_USD) as median_volume
from ethereum.aave.ez_withdraws
where block_timestamp::date >= current_date - {{N_Days}}
and symbol is not null
and symbol = 'AAVE'
group by 1,2,3)
,
final as ( select a.depositor_address, deposit_date, withdraw_date, a.volume as deposit_volume, b.volume as withdraw_volume
from deposit a join withdraw b on a.depositor_address = b.depositor_address
where b.volume <= a.volume)
,
final_2 as ( select datediff('day',deposit_date,withdraw_date) as days, depositor_address
from final)
select avg(days) as avg_holding
from final_2
where days >= 0
Run a query to Download Data