staderUsers transferring SD token from wormhole
    Updated 2022-07-07
    with trans as
    (select
    event_attributes:"to"::string as user,
    sum(event_attributes:"0_amount"::float/pow(10,8)) as SD_transfered_to_terra
    from terra.msg_events
    where
    tx_status = 'SUCCEEDED'
    and event_type = 'wasm'
    and event_attributes:"0_contract_address"::string in ('terra10nmmwe8r3g99a9newtqa7a75xfgs2e8z87r2sf')
    and event_attributes:"0_action"::string in ('complete_transfer_wrapped')
    and event_attributes:"contract"::string in ('terra1ustvnmngueq0p4jd7gfnutgvdc6ujpsjhsjd02')
    group by 1
    ),

    stake as (
    select
    msg_value:sender::string as user,
    sum(msg_value:execute_msg:send:amount::float/pow(10,8)) as whSD_staked
    from terra.msgs
    where
    msg_value:contract::string in ('terra1ustvnmngueq0p4jd7gfnutgvdc6ujpsjhsjd02')
    and tx_status = 'SUCCEEDED'
    and user in (select user from trans)
    and msg_value:execute_msg:send is not null
    and msg_value:execute_msg:send:contract::string in ('terra1tcgehea9034fne4g237rh45hcema89z3k58syt')
    and msg_value:execute_msg:send:msg::string in ('eyJkZXBvc2l0Ijp7fX0=')
    --and msg_value:execute_msg:send:amount::float/pow(10,8)>0
    group by 1
    ),

    consolidated as (
    select
    trans.user as user,
    SD_transfered_to_terra,
    coalesce(whSD_staked,0) as whSD_staked
    from trans