Flipside Team8 - Eclipse - Primary Asset Deposits
    Updated 2024-12-04
    with tokens as (

    select * from ( values
    ('USDC', 'USD Coin', 'AKEWE7Bgh87GPp171b4cJPSSZfmZwQ3KaqYqXoKLNAEE', 'Hke78vy1Mzzt5eEJ2jMeKtdqddedDe2rmzjsq16p9ETW', '9duB6N8ykhwwPZNEBztmLX4erd3dFXzTGGin7v1hNv5r', 'stable')
    , ('SOL', 'Solana', 'BeRUj3h7BqkbdfFU7FBNYbodgf8GCHodzKvF9aVjNNfL', '7mZCsut9beY53V9VWWovrRTBurGv6dozAmuhbwbyHsqk', 'MVZFBV7aC73GNedvy3u5geASWGAZkdHtFU16N5Hhddv', 'non-stable')
    , ('tETH', 'Turbo ETH', 'GU7NS9xCwgNPiAdJ69iusFrRfawjDDPjeMBovhV1d4kn', '8gEs8igcTdyrKzvEQh3oPpZm4HqNYozyczBCPQmZrsyp', null, 'non-stable')
    , ('ETH', 'Ethereum', 'So11111111111111111111111111111111111111112', NULL, '29w3f87B9gAkLY3m9rTsob67gvMbg58XsBCTTugMBgfN', 'primary')
    ) as t(symbol, name, mint, mint_wrapped, solend_pool_address, token_type)

    )

    , borrow_txs as (

    select
    block_timestamp
    , tx_id
    , symbol
    , instruction:accounts[0] as pool_account
    , instruction:accounts[1] as destination_account
    , instruction:accounts[7] as user_address
    , array_size(inner_instruction:instructions) as inner_size
    , iff(pool_account = '9duB6N8ykhwwPZNEBztmLX4erd3dFXzTGGin7v1hNv5r', 6, 9) as decimals
    , inner_instruction:instructions[inner_size - 1]:parsed:info:amount / pow(10, decimals) as amount
    , mint

    from eclipse.core.fact_transactions
    join eclipse.core.fact_events using(block_timestamp, tx_id)
    left join tokens on instruction:accounts[0] = solend_pool_address
    , lateral flatten(input => log_messages)

    where 1 = 1
    and block_timestamp > current_date - 30
    and program_id = 'So1endDq2YkqhipRh3WViPa8hdiSpxWy6z3Z6tMCpAo'
    and len(utils.udf_base58_to_hex(instruction:data)) > 4
    and value ilike 'Program log: Instruction: Borrow%'
    and inner_instruction:instructions[inner_size - 1]:parsed:info:authority = '5Gk1kTdDqqacmA2UF3UbNhM7eEhVFvF3p8nd9p3HbXxk' -- solend pool authority
    QueryRunArchived: QueryRun has been archived