MahrooUntitled Query
    Updated 2022-08-03
    with solt as (
    select date_trunc(week,block_timestamp) as date,signers[0] as borrower,
    sum(inner_instruction:instructions[1]:parsed:info:amount/1e9) as sol_borrowed
    from solana.fact_events join solana.core.fact_transactions using (tx_id)
    where program_id = 'So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo'--
    --and inner_instruction:instructions[1]:parsed:info:authority = 'DdZR6zRFiUt4S5mg7AV1uKB2z1f1WzcNYCaTEEWPAuby'
    and pre_token_balances[0]:mint = 'So11111111111111111111111111111111111111112'
    and succeeded = 'TRUE'
    group by 1,2),

    usdct as (select date_trunc(week,block_timestamp) as date,signers[0] as borrower,
    sum(inner_instruction:instructions[1]:parsed:info:amount/1e6) as usdc_borrowed
    from solana.fact_events join solana.core.fact_transactions using (tx_id)
    where program_id = 'So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo'--
    --and inner_instruction:instructions[1]:parsed:info:authority = 'DdZR6zRFiUt4S5mg7AV1uKB2z1f1WzcNYCaTEEWPAuby'
    and pre_token_balances[0]:mint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
    and succeeded = 'TRUE'
    group by 1,2),

    solpricet as (select block_timestamp::date as date,
    avg(swap_to_amount/swap_from_amount) as sol_price
    from solana.fact_swaps
    where swap_from_mint = 'So11111111111111111111111111111111111111112' --wSOL
    and swap_to_mint = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v' --USDC
    and swap_to_amount > 0
    and swap_from_amount > 0
    and succeeded = 'TRUE'
    group by 1),

    base as (select t1.date,
    t1.borrower as user1,
    sol_borrowed * sol_price as sol_borrowed_in_usd,
    usdc_borrowed
    from solt t1 join usdct t2 on t1.date = t2.date join solpricet t3 on t1.date = t3.date)

    select date,
    Run a query to Download Data