John_Galt2 Daily yLuna in Farm Net change by Date
    Updated 2022-07-07
    with table1 as (SELECT
    date(block_timestamp) as date,
    sum(event_attributes:"1_amount") / pow(10, 6) as in_yluna_farm --into yluna farm
    from terra.msg_events
    where event_attributes:"1_to" = 'terra1p7jp8vlt57cf8qwazjg58qngwvarmszsamzaru'
    and event_attributes:"1_action" = 'yluna_farming_bond'
    and event_index = 3
    group by 1
    ),
    table2 as (SELECT
    date(block_timestamp) as date,
    sum(event_attributes:"0_amount") / pow(10, 6) as out_yluna_farm -- out of yluna farm staking
    from terra.msg_events
    where event_attributes:"0_from" = 'terra1p7jp8vlt57cf8qwazjg58qngwvarmszsamzaru'
    and event_attributes:"0_action" = 'yluna_farming_unbond'
    and event_index = 3
    group by 1
    )
    select table1.date, table1.in_yluna_farm, table2.out_yluna_farm,
    table1.in_yluna_farm - table2.out_yluna_farm as net_yluna_added,
    sum(net_yluna_added) over (order by table1.date) as cumulative_yluna
    from table1
    left outer join table2 on table1.date = table2.date
    order by date