Sandeshcorr
Updated 2022-09-22Copy 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 stake as
(
select block_timestamp::date as "date", sum(raw_amount)/1e18 as deposit from ethereum.core.fact_token_transfers
where contract_address='0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'
and to_address='0x5e3ef299fddf15eaa0432e6e66473ace8c13d908'
-- and block_timestamp::date >= '2022-07-01'
group by "date"
order by "date" asc
),
unstake as
(
select block_timestamp::date as "date",
sum(raw_amount)/1e18 as unstake from ethereum.core.fact_token_transfers
where contract_address='0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'
and from_address=lower('0x5e3ef299fddf15eaa0432e6e66473ace8c13d908')
-- and block_timestamp::date >= '2022-07-01'
group by "date"
order by "date" asc
),
total as
(
select s."date",s.deposit as deposit, u.unstake as unstaked, (s.deposit)-(u.unstake) as current_contribution,
sum(current_contribution) over( order by s."date" asc ) as staked
from stake s inner join unstake u
on s."date"=u."date"
),
price as
(
select hour::date as "date",token_address, avg(price) as matic_price from ethereum.core.fact_hourly_token_prices
where token_address in (
lower('0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0')
)
group by "date", token_address
), temp as (
select t.*,p.matic_price,
p.matic_price - lag(p.matic_price) over( order by p."date" asc) as price_diff
Run a query to Download Data