John_Galt2 yLuna in Farm Net change by Address
    Updated 2022-07-07
    with table1 as (SELECT
    event_attributes:"0_from"::string as sending_address,
    sum(event_attributes:"1_amount") / pow(10, 6) as in_yluna_farm --into yluna farm
    from terra.msg_events
    where date(block_timestamp) > '2022-02-01'
    and event_attributes:"1_to" = 'terra1p7jp8vlt57cf8qwazjg58qngwvarmszsamzaru'
    and event_attributes:"1_action" = 'yluna_farming_bond'
    and event_index = 3
    group by 1
    ),
    table2 as (SELECT
    event_attributes:"1_to"::string as receiving_address,
    sum(event_attributes:"0_amount") / pow(10, 6) as out_yluna_farm -- out of yluna farm staking
    from terra.msg_events
    where date(block_timestamp) > '2022-02-01'
    and event_attributes:"0_from" = 'terra1p7jp8vlt57cf8qwazjg58qngwvarmszsamzaru'
    and event_attributes:"0_action" = 'yluna_farming_unbond'
    and event_index = 3
    group by 1
    )
    select table1.sending_address, table1.in_yluna_farm, table2.out_yluna_farm,
    table1.in_yluna_farm - COALESCE(table2.out_yluna_farm, 0) as remaining_yluna
    from table1
    left outer join table2 on table1.sending_address = table2.receiving_address
    where remaining_yluna > 50
    order by remaining_yluna desc
    Run a query to Download Data