binhachonTerra LP-ers: Aftermath - Swap
    Updated 2022-06-21
    with address_list as (
    select
    distinct from_address
    from (
    select
    from_address,
    pool_name,
    sum(case when lp_action = 'add_liquidity' then stake_units else -stake_units end) as stake_units
    from flipside_prod_db.thorchain.liquidity_actions
    where pool_name like 'TERRA.%'
    and from_address like 'thor%'
    and block_timestamp::date <= '2022-05-20'
    group by 1, 2
    )
    where stake_units > 0
    ),
    last_date as (
    select
    max(block_timestamp) as last_date
    from flipside_prod_db.thorchain.liquidity_actions
    where pool_name like 'TERRA.%'
    and block_timestamp::date <= '2022-05-12'
    ),
    latest_actions as (
    select
    address,
    max(latest_action) as latest_action
    from (
    select
    from_address as address,
    max(block_timestamp) as latest_action
    from flipside_prod_db.thorchain.swaps
    where address in (select from_address from address_list)
    group by 1
    union all
    select
    Run a query to Download Data