cheeyoung-kekvelo daily tvl
Updated 2022-08-16Copy Reference Fork
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
35
36
›
⌄
with all_in as(
select
day,
case when in_usd is null then -1*out_usd when out_usd is null then in_usd else in_usd-out_usd end as total_volume,
sum(case when in_usd is null then 1*out_usd when out_usd is null then in_usd else in_usd-out_usd end) over (order by day) as tvl
from (
select
b.day::date day,
in_usd as in_usd,
out_usd as out_usd
from (
select
date_trunc('day',block_timestamp) as day ,
sum(case
when token0_amount_usd is null then 2*token1_amount_usd
when token1_amount_usd is null then 2*token0_amount_usd
else coalesce(token0_amount_usd, 0) + coalesce(token1_amount_usd,0) end) as in_usd
from optimism.velodrome.ez_lp_actions
where lp_action = 'deposit'
group by 1
) b
full join (
select
date_trunc('day',block_timestamp) as day ,
sum( case
when token0_amount_usd is null then 2*token1_amount_usd
when token1_amount_usd is null then 2*token0_amount_usd
else coalesce(token0_amount_usd, 0) + coalesce(token1_amount_usd,0) end )as out_usd
from optimism.velodrome.ez_lp_actions
where lp_action = 'withdraw'
group by 1
) a
Run a query to Download Data