

 -- 1. 获取某些wallet 针对某一个token的 在一定时间段中每一次swap的信息 ， 价格，买卖量，sol量等
 -- 2. 获取 某一个token的 在一定时间段中每一次swap的信息 ， 价格，买卖量，sol量等
 

with
    input_address (address) as (
        values
('4cefnAL34KurvDSv8StgQtukXJpzQax8r7rPcfAiH1q1'),
('77RWuJjzTgswsgUafvhSNDAbGxHcUHQPZ3ogpvNr3eB'),
('42cyTW8WskqXcxubd7ubKkHAsdg6EYWXCSsGAox5AKbg'),
('5xbbZ1rM8KF1vvoWCgX3Z6vUcPF4gqFp9cdVet8y8DJ'),
('9KVcXs5Z64s4sCjo3UWKQGCxQsPjqQ7M4uRJdHngiDB2'),
('EN3uG7hkyNsWNujTQbxEcCtowpurKCQj4HMNCRegM1pP'),
('CzSoBsk4TXNuFx59fFv3MDN6QiHrBZDxf1iRvPdHbfRH'),
('Ex2Th2Wnf535mabJTUuxssD9Cpg6QRry1yYHM65K5sSp'),
('EZVibEmShfkTA3bmosJzZ78cE1ZT8vRaK3ErNcLFKese'),
('6GZyjgbvKnWWWfWBvdNGMXp8vwvKvLUyaR3VvKYz45Fp'),
('5pW6xYQZxZLs67eKuurGcTVm2nHqFcDsiuxesqagoW6V'),
('7Fxp3e8xdqcSQstyzMHySAR3ZEz2W9Sbvy9gmZAJb44X'),
('J4L3HPTKC1EkeXCwkLtsipAryeB3H6Y4fWgnpejKh6a3'),
('CB3HH9v3aDZocy9npe7TyTKfDEBotBmcgPjPDF3ip4qK'),
('DUFoRbB7B7UmvuzntS4CYexy2Sopz3dvjii97DD4rPgn'),
('4Bc1Mwa4ww8HUfHpoHfqroFEy7ChKvGi4E51Mj6rnMo9'),
('7CMXzsRqrVakVE3Fyw3YrNCSCGw5LSm4LRD4yRX9epgp'),
('6aEgy4QnbQ9EvLdoSpToRApUZyrpwfEXu1AaCVFAmiei'),
('4RyoEkX1mYN44t8JSKg5bUsgzmLFJfg3jpr2yrEaTTrm'),
('CwgHkUs6FS9ZYmBaiJd9UC9SNSpTugm26FfRuLdCRDWS'),
('6deMq6kL7Lb83d9fDj5ok3yTePFejuKmm99eJMbiR6V8'),
('9NNAetBQDgzcdUMjEmCLKEJ6AXKDAuJDEqNhvXgEmn4L'),
('D8h6fmowAvKEcCa5Lzbxc1S1pzDnF6CqUThswMPai7e7'),
('8CM48tGsNFTbsgoY4VQUJpxP5haMSHHc8RGv6v2dfsFf'),
('DiyANQnWP19XGJQC3ZTPcqSsHZr2MMMvByS4X5WCBUdv'),
('BKWksc6pM2AyNvFpV6JsKbnXMByNpJZU55JY8u39x3jM'),
('4F4feehMZiKnycW5q6vVrCWh4mX5v1zqAJu98gg3pDjS'),
('H46wBvv4U6acvSwkoWKZtQXn6Xkkg2z8Da7coL2ti5Sq'),
('9bi8EfPV8rawqFbcLPfjS7eDqdoozntv1k4Dy4bZkm4w'),
('9fw6g6vKSCLUSNBq5HsfsvyJ7U4AdrYVgqoHERWxHzPn'),
('E9YmnB4w1radAHCVxmXaTr1cV76cL3hZWz5qDoPa2PQU'),
('8tP1mVCiR4Wj9cX5jR5LCHGNwMoceBeFnujkZYZcfhNg'),
('3G5XWymznNjt7Eddg7REfKn5WhCG4M2XGvJsXq9b7bkE'),
('HKiiMjWDxvGXAYNFgoBvionfbaaXWnT79tn5z64tvmQk'),
('2xk8cNxt89guchaqGYxUkUSkFyfa7KFKdoPQLsAAwna9'),
('2MMYWhAYjTUmXg9nuUYUHkpaxiT91xCfLsNrSaZPMCDd'),
('D33VqQjk6cHtq4jiwbvFmdgKAaGi7R4AYUrcUr8FgffC'),
('2yhNdbgU76LzkFUdjxsLDpN4HrfiUo8TJ39nv5738ehj'),
('68F9fagj6aN6UZKn8h1NzTtN3xVYSDDecWoVyfFQyYgc'),
('iQu15wooderqSWhoETpjWFFQWH4gKPmudszrY54a1hu'),
('A2nAEus8FFPUmTX1gFD1KKKeYKkgW3dMCUGsCkht6kZL'),
('9YMfU2C9s9ok1nnLYFtYKp7FEUGQpgXq4wTbf3qxNny8'),
('HSQ8sfQB4f4Ws9ghxf3wvTqETXjmTMZioAwX2zhLhebZ'),
('21zKBzN6vC5vvueZ3H37m8BiKCKu1HB3hMnstbmJFKdN')

    ),
 
    swap_table as (
        select
            block_time,
            block_slot,
            tx_id,
            trade_source,
            project_main_id,
            token_bought_amount,
            token_sold_amount,
            token_bought_mint_address,
            token_sold_mint_address,
            trader_id
        from
            dex_solana.trades
        where
             block_time > timestamp '2025-01-07 00:00:00 +08:00'
            and block_time < timestamp '2025-01-07 23:05:00 +08:00'
            
            -- block_time > timestamp '2025-01-01 21:00:00 +08:00'
            -- and block_time < timestamp '2025-01-16 02:00:00 +08:00'
            and (
                (
                    token_bought_mint_address = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump'
                    and token_sold_mint_address = 'So11111111111111111111111111111111111111112'
                )
                or (
                    token_bought_mint_address = 'So11111111111111111111111111111111111111112'
                    and token_sold_mint_address = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump'
                )
            )
    ),
    swap_table_02 as (
        select
            block_time,
            block_slot,
            tx_id,
            trade_source,
            project_main_id,
            trader_id,
            (
                CASE
                    WHEN token_bought_mint_address = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump' THEN 'b'
                    ELSE 's'
                END
            ) AS action_type,
            (
                CASE
                    WHEN token_bought_mint_address = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump' THEN token_bought_amount
                    ELSE - token_sold_amount
                END
            ) AS token_swap_amount,
            (
                CASE
                    WHEN token_bought_mint_address = '5puhwnyz2Tv8jSmmBD5DSqCwFVXwwPGZacymM7DQpump' THEN - token_sold_amount
                    ELSE token_bought_amount
                END
            ) AS eth_swap_amount
        from
            swap_table
            -- 指定specila address
            inner join input_address on input_address.address = swap_table.trader_id
    ),
    swap_table_03 as (
        select
            trader_id,
            tx_id,
            block_time,
            block_slot,
            project_main_id,
            trade_source,
            action_type,
            round(token_swap_amount / 1e6, 4) as token_swap_M,
            round(eth_swap_amount, 2) as eth_swap_amount,
            round(- eth_swap_amount / token_swap_amount, 10) as pri
        from
            swap_table_02
        where
         abs(token_swap_amount)> 0.01 *1e6 
        
    )
select
    *
from
    swap_table_03
order by
    -- trader_id,
    block_time,
    block_slot asc