marqustablecoin borrows - aggregated
    Updated 2024-12-02
    with

    borrow_txs_marginfi as ( -- does not include flash loans

    select
    fact_decoded_instructions.block_timestamp
    , fact_decoded_instructions.tx_id
    , fact_token_balances.pre_balance - fact_token_balances.balance as amount
    , fact_token_balances.mint
    , 'MarginFi' as platform_name
    from solana.core.fact_decoded_instructions
    left join solana.core.fact_token_account_owners
    on fact_decoded_instructions.decoded_instruction :accounts[6] :pubkey = fact_token_account_owners.account_address -- Bank Liquidity Vault
    left join solana.core.fact_token_balances
    using(block_timestamp, tx_id, account_address, owner)
    where fact_decoded_instructions.program_id = 'MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA'
    and fact_decoded_instructions.event_type = 'lendingAccountBorrow'
    and block_timestamp ::date > current_date() - interval '30 days'
    ),

    borrow_txs_drift as (

    select

    block_timestamp
    , tx_id
    , amount
    , mint

    , replace(f_logs.value, 'Program data: ', '') as log_data
    , to_varchar(base64_decode_binary(log_data), 'HEX') AS hex_data

    , 'Drift' as platform_name
    QueryRunArchived: QueryRun has been archived