binhachon1. [Easy] Asset Transaction Volume - Trend?
    Updated 2021-11-21
    with mAsset_contracts as(
    select address, address_name from terra.labels
    where substr(address_name,1,11) = 'Terraswap m'
    ),
    mAsset_transactions as(
    -- swap UST for other asset
    select block_timestamp, event_attributes:"0_contract_address"::string as address,
    event_attributes:offer_amount::float/1e6 as UST_amount, event_attributes:return_amount::float/1e6 as masset_amount from terra.msg_events
    where event_type = 'from_contract'
    and tx_status = 'SUCCEEDED'
    and event_attributes:"0_contract_address"::string in (select address from mAsset_contracts)
    and event_attributes:"0_action"::string = 'swap'
    and event_attributes:offer_asset::string = 'uusd'
    union all
    -- swap other asset for UST
    select block_timestamp, event_attributes:"1_contract_address"::string as address,
    event_attributes:return_amount::float/1e6 as UST_amount, event_attributes:offer_amount::float/1e6 as masset_amount from terra.msg_events
    where event_type = 'from_contract'
    and tx_status = 'SUCCEEDED'
    and event_attributes:"1_contract_address"::string in (select address from mAsset_contracts)
    and event_attributes:"1_action"::string = 'swap'
    and event_attributes:ask_asset::string = 'uusd'
    )
    select blocktime, address_name, sum(ust_amount) over (partition by blocktime order by blocktime) as total_ust, ust_amount/total_ust * 100 as percentage from(
    select date_trunc('week', block_timestamp) as blocktime, sum(UST_amount) as ust_amount, address_name from mAsset_transactions left join mAsset_contracts on mAsset_transactions.address = mAsset_contracts.address
    where block_timestamp > getdate() - interval'90 days'
    group by blocktime, address_name
    )
    order by blocktime desc, percentage


    Run a query to Download Data