theericstoneborrowed ust destinations
    Updated 2022-04-27
    with rbs as (
    select
    block_timestamp,
    action_log:borrower::string as address,
    'borrow' as action_type,
    'anchor' as project_label,
    action_log:borrow_amount/pow(10,6) as amount
    from silver_terra.event_actions
    where block_timestamp > current_date - {{daysago}}
    and action_method = 'borrow_stable'
    and action_contract_address = 'terra1sepfj7s0aeg5967uxnfk4thzlerrsktkpelm5s'
    ),
    borrowers as (
    select distinct address from rbs
    ),
    actions as (
    select
    block_timestamp,
    sender as address,
    current_action as action_type,
    coalesce(recipient_label,'unlabeled transfer') as project_label,
    -1 * amount as amount
    from terra.transfer_events
    where block_timestamp > current_date - {{daysago}}
    and currency = 'UST'
    and sender IN (select address from borrowers)
    and initial_action <> 'borrow_stable'
    and current_action <> 'borrow_stable'
    ),
    allactions as (
    select * from rbs
    union
    select * from actions
    ),
    cbs as (
    select * from (
    Run a query to Download Data