Updated 2023-01-03
    --credit : https://app.flipsidecrypto.com/velocity/queries/f1dc2cc4-f80c-406b-adf7-e2ef71390fc3
    with maintable as (
    select block_timestamp,
    tx_id,
    tx_from,
    row_number () over (partition by tx_from order by block_timestamp) as rn
    from osmosis.core.fact_transactions),

    firsttwo as (
    select * from maintable
    where rn in ('1','2')),

    table1 as (
    select block_timestamp as swap_date,
    tx_id,
    trader,
    to_currency,
    to_amount,
    to_decimal
    from osmosis.core.fact_swaps
    where tx_id in (select tx_id from firsttwo where rn = '1')),

    table2 as (
    select block_timestamp as transfer_date,
    t1.tx_id,
    sender,
    currency,
    amount,
    decimal
    from osmosis.core.fact_transfers t1 join table1 t2 on t1.sender = t2.trader and t1.currency = t2.to_currency and t1.block_timestamp > t2.swap_date
    where transfer_type = 'IBC_TRANSFER_OUT'
    and t1.tx_id in (select tx_id from firsttwo where rn ='2')),

    table3 as (
    select block_timestamp as lp_date,
    t1.tx_id,
    Run a query to Download Data