KuramaCosmos - proposal 84
Updated 2022-12-11Copy Reference Fork
999
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
›
⌄
-- all delegation txs
with table_0 as (
select distinct tx_id from cosmos.core.fact_msg_attributes
where tx_succeeded = 'TRUE'
and msg_type = 'message'
and attribute_key = 'action'
and attribute_value = '/cosmos.staking.v1beta1.MsgDelegate'
),
-- all delegation txs + address
table_1 as (select distinct tx_id, attribute_value as address from cosmos.core.fact_msg_attributes
where tx_succeeded = 'TRUE'
and msg_type = 'transfer'
and attribute_key = 'sender'
and tx_id in (select * from table_0)),
-- all delegation txs + validator
table_2 as (select distinct tx_id, attribute_value as validator from cosmos.core.fact_msg_attributes
where tx_succeeded = 'TRUE'
and msg_type = 'delegate'
and attribute_key = 'validator'
and tx_id in (select * from table_0)),
-- all delegation txs + amount
table_3 as (select distinct tx_id, attribute_value as shares from cosmos.core.fact_msg_attributes
where tx_succeeded = 'TRUE'
and msg_type = 'delegate'
and attribute_key = 'new_shares'
and tx_id in (select * from table_0)),
all_delegations as (select address, b.validator, (sum(c.shares)/pow(10,6)) as amount from table_1 a
left join table_2 b
on a.tx_id = b.tx_id
left join table_3 c
on a.tx_id = c.tx_id
group by address, b.validator),
-- same as before but for undelegations
Run a query to Download Data