John_GaltAstro Staking by Address - need to fix this!
Updated 2022-04-20
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
›
⌄
with table1 as (select --- looks like the query gives what users have staked, excluding the bought-back astro put in by the protocol
date(block_timestamp) as date,
event_attributes:"from": as address,
event_attributes:"0_amount" / pow(10, 6) as astro_in,
null as astro_out
from terra.msg_events
where date(block_timestamp) > '2022-03-01'
and event_attributes:"0_to" = 'terra1f68wt2ch3cx2g62dxtc8v68mkdh5wchdgdjwz7'
and event_attributes:"1_action" = 'mint'
and event_index = 3
union all
select
date(block_timestamp) as date,
event_attributes:"1_to" as address,
null as astro_in,
event_attributes:"2_amount" / pow(10, 6) as astro_out
from terra.msg_events
where date(block_timestamp) > '2022-03-01'
and event_attributes:"1_from" = 'terra1f68wt2ch3cx2g62dxtc8v68mkdh5wchdgdjwz7'
and event_attributes:"1_action" = 'burn'
and event_index = 3
),
final as (select address, sum(astro_in) as inn, sum(astro_out) as outt, inn - outt as net_in
from table1
group by address
)
select row_number() over (order by net_in desc) as Rank, *
from final
where rank