ArioRainfi Loans part 2
    Updated 2024-06-15

    select
    block_timestamp,
    tx_id,
    fact_events.INNER_INSTRUCTION:instructions[1]:parsed:info:mint::string as NFT_Collection_address,
    F_Amount.value:parsed:info:authority as Lender,
    signers[0] as Borrower
    from
    solana.core.fact_events
    inner join solana.core.fact_transactions using(tx_id, block_timestamp, succeeded, block_id)
    inner join lateral flatten (
    input => solana.core.fact_transactions.log_messages
    ) f_logs
    cross join table(flatten(inner_instruction:instructions)) as F_Amount
    where
    1 = 1
    and fact_events.program_id = 'RainEraPU5yDoJmTrHdYynK9739GkEfDsE4ffqce2BR' --and contains(f_logs.value::variant, 'Program log: Instruction: TakeLoan')
    and regexp_replace(f_logs.value, '^Program log: Instruction: ') = 'TakeLoan'
    and F_Amount.value:parsed:info:destination = INSTRUCTION:accounts [2]
    and F_Amount.value:parsed:info:authority != signers [0]
    and F_Amount.value:parsed:type = 'transfer'
    and F_Amount.value:program = 'spl-token'
    and F_Amount.value:programId = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'
    and SUCCEEDED
    and BLOCK_TIMESTAMP :: date >= '2023-08-01'
    and BLOCK_TIMESTAMP :: date < '2024-02-29'
    QueryRunArchived: QueryRun has been archived