-- 获取一个token 在一段时间内的transfer 记录 获取A WALLET --> B WALLET  transfer次数以及amount 
with
    input_address (address) as (
    values
('Cet3TXGhtFcBo6vX9kfYjbtNyANbCWqwVC6G1QioKUhc'),
('7m2XQP2NDebaEKDhegj7WYpZBmrKF5yhiVi1JZU8cwoj'),
('68WLD7YzwjqBoCEVuJ3rjVbaPaAog6ATCkjUTpNqiMNF'),
('4ttYJgVcZMMXFsTPBAEKVUEDUshvsXqgvfUv3W7bdv7e'),
('Hh6XswyZK9WPUbb6csqi7YggDqYTstKkHFvvh7PFx7kw'),
('DAr4CE2rFgvtDHSFG75rEhmxmqgfEQYir91RGY458pkZ'),
('CC1xmUJCvq4wPzHSNKVHfMV9T3vRjHTZnzvW9VLVJ4gs'),
('GDwiC6S14topnYmWquQb6JdQxrRsvtH7N3K8UCLZmVrk'),
('HjUrUJi7zUCXu6NpXBUujYsoG5TJsXkPUrYJdWMKVtts'),
('5PZs2fmTJpjaMhYbdAH6uEx7Jbbhy2RdAdkNnPw83H3a'),
('FH8xnCwgoQgk3nXuePEdxYB5SZDTWSZav27smVcHjN1q'),
('ET3VpuSMr15ufn4z9a5kwHhyLRse2H96TY2HXVKZxCJM'),
('GD9Q87EY9guqAqkxgNwiqoqUKmBs958tcFEkQ8q1HD1N'),
('5pW6xYQZxZLs67eKuurGcTVm2nHqFcDsiuxesqagoW6V'),
('7V7BFFLNgHhrJq7Udm9Zi26Tbgvytg9GWKLdDLRzf4z6'),
('BC8yiFFQWFEKrEEj75zYsuK3ZDCfv6QEeMRif9oZZ9TW'),
('6QfdT1XZauUMCJU3SaN2d2aqdoFa4TDVNmxJig52ZGZT'),
('3M2dQzm6kz9ChDfaeX3xxqzn8BdeLjJEJv9JBd9WG2Jx'),
('6xMPaDn8jZ1r68BzXAunvumU8BTG2vDbgemNkWwRd1Fo'),
('3UFHt8qqRtHM2hZaCYRGKaF1gYfePcRYZFo2CdaadfMa'),
('Aewfbg61nn3SrFikqTsX2c8nZM8DXVbG7jpUp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TTqRoKN9Ea'),
('JD6GNPCYsrEe95dzbfvzWV548ATFBCiv1VpPTeivqtp'),
('38nYRZ7ENv1QNZgDk2d5rARsQroCDC6pRhJmCU8yVMbR'),
('43TMSiFPiw721VP6ue58Kc4cPocFuU1qju1ok9ibDsS6'),
('HmgJG6XqV4HjDEXG47gTx8oobq6Y5W11oeYBD86N2RPR'),
('ETXkmPKnSx8jPqGvvES5Ss3k9q811r7BuqPPwcKZn2pv'),
('YWzEJLhgobeRvYnqVhPRNRC36sEiB9KJWybkXdXoyyb')
  

    ),
    Exclude_onwer (owner) AS (
        VALUES
            ('5Q544fKrFoe6tsEbD7S8EmxGTJYAKtTVhAW5Q5pge4j1'), --  Raydium Authority V4
            ('BQ72nSv9f3PRyRKCBnHLVrerrv37CYTHm5h3s9VSGQDV'), -- Jupiter Aggregator Authority 1
            ('2MFoS3MPtvyQ4Wh4M9pdfPjz6UhVoNbFbGJAskCPCj3h'), -- Jupiter Aggregator Authority 2
            ('HU23r7UoZbqTUuh3vA7emAGztFtqwTeVips789vqxxBw'), -- Jupiter Aggregator Authority 3
            ('3CgvbiM3op4vjrrjH2zcrQUwsqh5veNVRjFCB9N6sRoD'), -- Jupiter Aggregator Authority 4
            ('6LXutJvKUw8Q5ue2gCgKHQdAN4suWW8awzFVC6XCguFx'), -- Jupiter Aggregator Authority 5
            ('CapuXNQoDviLvU1PxFiizLgPNQCxrsag1uMeyk6zLVps'), -- Jupiter Aggregator Authority 6
            ('GGztQqQ6pCPaJQnNpXBgELr5cs3WwDakRbh1iEMzjgSJ'), -- Jupiter Aggregator Authority 7
            ('9nnLbotNTcUhvbrsA6Mdkx45Sm82G35zo28AqUvjExn8'), -- Jupiter Aggregator Authority 8
            ('3LoAYHuSd7Gh8d7RTFnhvYtiTiefdZ5ByamU42vkzd76'), -- Jupiter Aggregator Authority 9
            ('DSN3j1ykL3obAVNv7ZX49VsFCPe4LqzxHnmtLiPwY6xg'), -- Jupiter Aggregator Authority 10
            ('69yhtoJR4JYPPABZcSNkzuqbaFbwHsCkja1sP1Q2aVT5'), -- Jupiter Aggregator Authority 11
            ('6U91aKa8pmMxkJwBCfPTmUEfZi6dHe7DcFq2ALvB2tbB'), -- Jupiter Aggregator Authority 12
            ('7iWnBRRhBCiNXXPhqiGzvvBkKrvFSWqqmxRyu9VyYBxE'), -- Jupiter Aggregator Authority 13
            ('4xDsmeTWPNjgSVSS1VTfzFq3iHZhp77ffPkAmkZkdu71'), -- Jupiter Aggregator Authority 14
            ('GP8StUXNYSZjPikyRsvkTbvRV1GBxMErb59cpeCJnDf1'), -- Jupiter Aggregator Authority 15
            ('HFqp6ErWHY6Uzhj8rFyjYuDya2mXUpYEk8VW75K9PSiY'), -- Jupiter Aggregator Authority 16
            ('45ruCyfdRkWpRNGEqWzjCiXRHkZs8WXCLQ67Pnpye7Hp'), -- Jupiter Partner Referral Fee Vault
            ('ZG98FUCjb8mJ824Gbs6RsgVmr1FhXb2oNiJHa2dwmPd'), -- CxvksNjwhdHDLr3qbCXNKVdeYACW8cs93vFqLqtgyFE5's fee account
            ('DGT9TPRGQwpJeMvDdZJDEaVRZa2ZMXtp16pGZgAgBoLx') -- pump Bonding Curve
           
            ,('GE5PnwZTgWw1YqVGno2QPWqie6aLjswNeGFhiF1nDg3k') -- Raydium (8008-USDC) Market

            ,('25mYnjJ2MXHZH6NvTTdA63JvjgRVcuiaj6MRiEQNs1Dq')  -- okx 相关
            ,('14qLxu9XDQtc2pgnxX2SSdWPpnuVrEqccgwmATH1khcY')  -- Raydium (SOL-8008) Market
            ,('5YET3YapxD6to6rqPqTWB3R9pSbURy6yduuUtoZkzoPX')  -- Jupiter ApePro Keeper
            ,('F5sw1r94VXmUGwesPrcY3TvwSrfVAZmRaWwMtD1tr3Yf')  -- Meteora (8008-SOL) Market   
            ,('j1oAbxxiDUWvoHxEDhWE7THLjEkDQW2cSHYn2vttxTF') --jupiter limit order taker account
            ,('4KaVawPKmG1RZCv698XD9YzRsJcFPXrEoYnZbdZmfFFq')  --okx相关
            ,('j1oeQoPeuEDmjvyMwBmCWexzCQup77kbKKxV59CnYbd') --jupiter limit order taker account
            ,('6KFVj2czLwNQeE4yBgFau6LHUS72vqgP11Sv1JUNxghz')  --fee account
       
        
    ),
    transfers_01 AS (
        SELECT
            -- sum(amount) AS amount,
            tx_id,
            block_time,
            block_slot,
            round(amount / 1e6, 2) / 1e6 as token_transfer_M,
            from_owner,
            to_owner,
            from_token_account,
            to_token_account
        FROM
            tokens_solana.transfers
        WHERE
            block_time >= (TIMESTAMP '2025-01-01 00:00:00 +08:00')
            AND block_time < (TIMESTAMP '2025-01-16 02:00:00 +08:00')
            AND token_mint_address = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump'
            AND action = 'transfer'
            AND (
                from_owner NOT IN (
                    SELECT
                        owner
                    FROM
                        Exclude_onwer
                )
                AND to_owner NOT IN (
                    SELECT
                        owner
                    FROM
                        Exclude_onwer
                )
            )
            AND (
                from_owner IN (
                    SELECT
                        address
                    FROM
                        input_address
                )
                OR to_owner IN (
                    SELECT
                        address
                    FROM
                        input_address
                )
            )
    )
SELECT
    tx_id,
    block_time,
    block_slot,
    token_transfer_M,
    from_owner,
    to_owner
FROM
    transfers_01
order by
    block_time,
    block_slot asc
    --
    --
    --
    -- 
    --   -- 总体的transfer记录
    -- ,
    --   transfers_total AS (
    --     SELECT
    --       sum(token_transfer_M) AS amount,
    --       from_owner AS from_owner,
    --       to_owner AS to_owner,
    --       from_token_account,
    --       to_token_account,
    --       count (*)  AS owner_count
    --     FROM
    --       transfers_01
    --     GROUP BY
    --       from_token_account,
    --       to_token_account,
    --        from_owner,
    --       to_owner
    --   )
    -- SELECT
    --   amount,
    --   from_owner,
    --   to_owner,
    --   from_token_account,
    --   to_token_account,
    --   owner_count
    -- FROM
    --   transfers_total