HosseinUntitled Query
    Updated 2022-12-13
    with prices as (
    select trunc(block_timestamp::date, 'day') as day,
    from_currency as currency,
    avg ((to_amount / pow(10, to_decimal))/(from_amount/pow(10, from_decimal))) as price_usd
    from osmosis.core.fact_swaps
    where from_currency in ('uosmo', 'ibc/3FF92D26B407FD61AE95D975712A7C319CDE28DE4D80BDC9978D935932B991D7')
    and to_currency in ('ibc/D189335C6E4A68B513C10AB227BF1C1D38C746766278BA3EEB4FB14124F1D858', 'ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7') -- USDC, DAI
    and to_amount > 0
    and from_amount > 0
    and tx_status = 'SUCCEEDED'
    group by 1, 2
    ),

    t1 as (
    select
    liquidity_provider_address as lprovider,
    count (distinct tx_id) as existed_lproviders_tx_count,
    sum ((amount * price_usd) / power(10, decimal)) as exited_total_amount
    from osmosis.core.fact_liquidity_provider_actions a
    join prices
    on prices.day = a.block_timestamp::date
    and prices.currency = a.currency
    where action = 'pool_exited'
    and pool_id [0] = '773'
    and tx_status = 'SUCCEEDED'
    group by 1
    having existed_lproviders_tx_count > 5
    ),

    t2 as (
    select
    liquidity_provider_address as lprovider,
    count (distinct tx_id) as joined_lproviders_tx_count,
    sum ((amount * price_usd) / power(10, decimal)) as joined_total_amount
    from osmosis.core.fact_liquidity_provider_actions a
    join prices
    Run a query to Download Data