staderwhSD
    Updated 2022-07-07
    with claim as (
    select
    msg_value:sender::string as user,
    sum(msg_value:execute_msg:claim:amount::float/pow(10,8)) as SD_claimed
    from terra.msgs
    where
    msg_value:contract::string in ('terra127679wwl2glzc4cv7zu6rsp7062xuw5dnlt993')
    and tx_status = 'SUCCEEDED'
    and msg_value:execute_msg:claim is not null
    group by 1
    ),

    stake as (
    select
    msg_value:sender::string as user,
    sum(msg_value:execute_msg:send:amount::float/pow(10,8)) as SD_staked
    from terra.msgs
    where
    msg_value:contract::string in ('terra1ustvnmngueq0p4jd7gfnutgvdc6ujpsjhsjd02')
    and tx_status = 'SUCCEEDED'
    and user in (select user from claim)
    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
    claim.user as user,
    SD_claimed,
    coalesce(SD_staked,0) as SD_staked
    from claim
    left join stake
    on claim.user = stake.user
    Run a query to Download Data