Flipside Communityjupiter dca routes using fact transactions
    Updated 2024-01-31
    /**
    Given:
    - program id 'DCA265Vj8a9CEuX1eb1LWRnDT7uK6q1xMipnNyatn23M' (Jupiter DCA)
    - event name 'openDca' (or 'openDcaV2')
    - sample tx id '2wc4aT9eDvejvJUjd4Gx1NDwbidTi2EXkPNKtDxSDvj3dRgwAvmhMp2fDCb1qGhjEtgAp6JeM6f8Lnoc7aYRwh9B' on 2023-12-31
    - query below that uses the new "solana.core.fact_decoded_instructions" table to get:
    in and out token address pairs, and for each pair the number of DCAs initiated and the total amount in

    Task:
    - Write a query to get the same result without using
    "solana.core.fact_decoded_instructions",
    e.g. just using fact_transactions or fact_events
    **/


    WITH dca AS (
    SELECT
    block_timestamp,
    tx_id,
    decoded_instruction :name :: STRING AS event_name,
    decoded_instruction :accounts [1] :pubkey :: STRING AS USER,
    decoded_instruction :accounts [2] :pubkey :: STRING AS in_mint,
    decoded_instruction :accounts [3] :pubkey :: STRING AS out_mint,
    decoded_instruction :args :cycleFrequency :: INT AS cycle_freq_secs,
    decoded_instruction :args :inAmount :: INT AS total_dca_amount,
    decoded_instruction :args :inAmountPerCycle :: INT AS dca_per_cycle
    FROM
    solana.core.fact_decoded_instructions
    WHERE
    block_timestamp :: DATE >= CURRENT_DATE() - INTERVAL '1 months'
    AND program_id = 'DCA265Vj8a9CEuX1eb1LWRnDT7uK6q1xMipnNyatn23M'
    AND decoded_instruction :name :: STRING = 'openDca'
    UNION ALL
    SELECT
    block_timestamp,
    tx_id,
    Last run: about 1 year ago
    IN_MINT
    OUT_MINT
    TOTAL_DCA_IN
    NUM_OPEN_DCA
    1
    EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vSo1111111111111111111111111111111111111111233420471.38443417989
    2
    UxxvnMnUGoXJig9wc8phE1mYJZMFq3hpfr259zMWcq4JxxWsvm9jHt4ah7DT9NuLyVLYZcZLUdPD93PcPQ71Ka288879467.1622115764
    3
    EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vWENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk16291601.71331514047
    4
    EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vJUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN88891496.96670311790
    5
    So11111111111111111111111111111111111111112EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v253322.543082558679
    6
    So11111111111111111111111111111111111111112WENWENvqqNya429ubCdR81ZmD69brwQaaBYY6p3LCpk55763.1756330927695
    7
    EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1vEs9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB3444683.7568526686
    8
    Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYBEPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v3956467.7611876450
    9
    JxxWsvm9jHt4ah7DT9NuLyVLYZcZLUdPD93PcPQ71KaUxxvnMnUGoXJig9wc8phE1mYJZMFq3hpfr259zMWcq423912133.84063754602
    10
    So11111111111111111111111111111111111111112JUPyiwrYJFskUPiHa7hkeR8VUtAeFoSYbKedZNsDvCN107014.6811986233963
    10
    1KB
    5s