dsaberUSDC ownership query
    Updated 2022-09-29
    WITH daily_usdc_owners_pre AS (
    SELECT block_date
    ,usdc_owner
    ,COALESCE(usdc_pre_amount, 0) AS usdc_pre_amount
    FROM (
    SELECT block_timestamp::DATE AS block_date
    ,t.value['owner'] AS usdc_owner
    ,t.value['uiTokenAmount']['amount']/1e6 AS usdc_pre_amount
    ,ROW_NUMBER() OVER (PARTITION BY t.value['owner'], block_timestamp::DATE ORDER BY block_timestamp) AS rnk
    FROM solana.core.fact_transactions,
    LATERAL FLATTEN(pre_token_balances) AS t
    WHERE block_timestamp::DATE >= CURRENT_DATE - 30
    AND block_timestamp::DATE < CURRENT_DATE
    AND succeeded
    AND array_size(pre_token_balances) >= 1
    AND t.value['mint'] = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
    )
    WHERE rnk = 1
    )
    ,daily_usdc_owners_post AS (
    SELECT block_date
    ,usdc_owner
    ,COALESCE(usdc_post_amount, 0) AS usdc_post_amount
    FROM (
    SELECT block_timestamp::DATE AS block_date
    ,t.value['owner'] AS usdc_owner
    ,t.value['uiTokenAmount']['amount']/1e6 AS usdc_post_amount
    ,ROW_NUMBER() OVER (PARTITION BY t.value['owner'], block_timestamp::DATE ORDER BY block_timestamp DESC) AS rnk
    FROM solana.core.fact_transactions,
    LATERAL FLATTEN(post_token_balances) AS t
    WHERE block_timestamp::DATE >= CURRENT_DATE - 30
    AND block_timestamp::DATE < CURRENT_DATE
    AND succeeded
    AND array_size(post_token_balances) >= 1
    AND t.value['mint'] = 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'
    )