cristinatintocosmos redelegations
    Updated 2022-12-14
    with
    tab1 as (
    select tx_id,attribute_value as proposal_id
    from cosmos.core.fact_msg_attributes
    where msg_type='proposal_vote' and attribute_key='proposal_id' and tx_succeeded = 'TRUE' and attribute_value=82
    ),
    tab2 as (
    select block_timestamp,
    tx_id,
    attribute_value as wallet
    from cosmos.core.fact_msg_attributes
    where ATTRIBUTE_KEY= 'spender' and tx_id in (select tx_id from tab1)
    ),
    tab3 as (
    select block_timestamp,
    tx_id,
    82 proposal,
    case when attribute_value='VOTE_OPTION_YES' or attribute_value like '%{"option":1%' then 'Yes'
    when attribute_value='VOTE_OPTION_NO' or attribute_value like '%{"option":3%' then 'No'
    when attribute_value='VOTE_OPTION_NO_WITH_VETO' or attribute_value like '%{"option":4%' then 'No with veto'
    else 'Abstain' end as vote_option
    from cosmos.core.fact_msg_attributes
    where ATTRIBUTE_KEY= 'option' and tx_id in (select tx_id from tab1)
    having vote_option is not null
    ),
    tab4 as (
    select y.block_timestamp,
    x.tx_id,
    wallet,
    vote_option,
    proposal
    from tab1 x join tab2 y on x.tx_id = y.tx_id
    join tab3 z on x.tx_id = z.tx_id
    ),
    tab5 as (
    Run a query to Download Data