cypherWhat Happens To Liquidated Collateral?
    Updated 2022-04-17
    with addresses as (select
    block_timestamp,
    tx_id,
    iff(event_attributes:to is null, event_attributes:"1_to", event_attributes:to ) as address,
    -- iff(event_attributes:"3_amount" is null, event_attributes:collateral_amount/1e6, event_attributes:"3_amount"/1e6) as liquidated_amount,
    iff(event_attributes:"3_amount" is null, event_attributes:collateral_amount, event_attributes:"3_amount") as liquidated_amount_real
    from terra.msg_events
    where block_timestamp >= current_date() - 30
    and event_attributes:"0_action" = 'claim_liquidations'
    and event_attributes:collateral_token = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp'
    and event_type = 'wasm'),

    provide_collateral as (select
    block_timestamp,
    tx_id,
    event_attributes:"0_borrower" as address,
    event_attributes:amount/1e6 as collateral_amount,
    event_attributes:amount as collateral_amount_real
    from terra.msg_events
    where block_timestamp >= current_date() - 30
    and event_attributes:"0_action" = 'lock_collateral'
    and event_type = 'wasm'),

    swap_ust as (select
    block_timestamp,
    tx_id,
    event_attributes:"0_from" as address,
    event_attributes:"0_amount"/1e6 as swap_amount,
    event_attributes:"0_amount" as swap_amount_real
    from terra.msg_events
    where block_timestamp >= current_date() - 30
    and event_attributes:"0_offer_asset" = 'terra1kc87mu460fwkqte29rquh4hc20m54fxwtsx7gp'
    and event_attributes:"0_ask_asset" = 'uluna' and event_attributes:"1_ask_asset" = 'uusd'
    and event_attributes:"0_to" = 'terra16t7dpwwgx9n3lq6l6te3753lsjqwhxwpday9zx'
    and event_attributes:"1_to" = 'terra1j66jatn3k50hjtg2xemnjm8s7y8dws9xqa5y8w'
    and event_type = 'wasm'),
    Run a query to Download Data