Kurama2023-04-25 01:39 PM
    Updated 2023-04-25
    with all_tx_red_bank as (select distinct tx_id as tx_id from osmosis.core.fact_msg_attributes
    where attribute_value = 'osmo1c3ljch9dfw5kf52nfwpxd2zmj2ese7agnx0p9tenkrryasrle5sqf3ftpg'
    ),

    all_tx_repay as (
    select distinct tx_id as tx_id from osmosis.core.fact_msg_attributes
    where tx_id in (select * from all_tx_red_bank)
    and attribute_key = 'action'
    and attribute_value = 'repay'
    ),

    all_tx_borrow as (
    select distinct tx_id as tx_id from osmosis.core.fact_msg_attributes
    where tx_id in (select * from all_tx_red_bank)
    and attribute_key = 'action'
    and attribute_value = 'borrow'
    ),

    all_tx_deposit as (
    select distinct tx_id as tx_id from osmosis.core.fact_msg_attributes
    where tx_id in (select * from all_tx_red_bank)
    and attribute_key = 'action'
    and attribute_value = 'deposit'
    ),

    all_tx_withdraw as (
    select distinct tx_id as tx_id from osmosis.core.fact_msg_attributes
    where tx_id in (select * from all_tx_red_bank)
    and attribute_key = 'action'
    and attribute_value = 'withdraw'
    ),

    borrowing as (
    select 'Borrow' as action, date_trunc('hour', block_timestamp) as date, SUBSTRING(attribute_value, CHARINDEX('ibc/',attribute_value), LEN(attribute_value)) as ibc, b.project_name, sum(to_number(SUBSTRING(attribute_value,0,CHARINDEX('ibc/',attribute_value)-1))/pow(10, b.decimal)) as amount from osmosis.core.fact_msg_attributes a
    left join osmosis.core.dim_tokens b
    on SUBSTRING(attribute_value, CHARINDEX('ibc/',attribute_value), LEN(attribute_value)) = b.address
    Run a query to Download Data