sofiatUNISWAP WITHDRAWAL
    Updated 2022-11-28
    WITH TOTAL AS (SELECT BLOCK_TIMESTAMP, TX_HASH, LIQUIDITY_PROVIDER, ACTION, POOL_NAME,
    CASE WHEN TOKEN0_SYMBOL = 'WETH' THEN AMOUNT0_ADJUSTED
    WHEN TOKEN1_SYMBOL ='WETH' THEN AMOUNT1_ADJUSTED END AS AMOUNT
    FROM ethereum.uniswapv3.ez_lp_actions
    WHERE TOKEN0_SYMBOL ='WETH' OR TOKEN1_SYMBOL ='WETH' AND
    BLOCK_TIMESTAMP::DATE >= '2022-07-01' AND AMOUNT > 0 ),

    DEPOSITOR AS (SELECT DATE_TRUNC('DAY', BLOCK_TIMESTAMP) AS BLOCK_DAY, SUM(AMOUNT) AS TOTAL_DEPOSIT, COUNT(DISTINCT TX_HASH) AS TOTAL_D_HASH,
    COUNT(DISTINCT LIQUIDITY_PROVIDER) AS DEPOSITORS
    FROM TOTAL
    WHERE ACTION ='INCREASE_LIQUIDITY' AND BLOCK_DAY >= '2022-07-01'
    GROUP BY BLOCK_DAY),

    WITHDRAW AS (SELECT DATE_TRUNC('DAY', BLOCK_TIMESTAMP) AS BLOCK_DAY, SUM(AMOUNT) AS TOTAL_WITHDRAW, COUNT(DISTINCT TX_HASH) AS TOTAL_W_HASH,
    COUNT(DISTINCT LIQUIDITY_PROVIDER) AS WITHDRAWERS
    FROM TOTAL
    WHERE ACTION ='DECREASE_LIQUIDITY' AND BLOCK_DAY >= '2022-07-01'
    GROUP BY BLOCK_DAY),

    M_DETAILS AS (SELECT D.BLOCK_DAY, CASE WHEN D.BLOCK_DAY >= '2022-09-01' AND D.BLOCK_DAY < '2022-09-15' THEN 'TWOWEEKS_BM'
    WHEN D.BLOCK_DAY < '2022-09-01' THEN 'BEFORE_MERGE' ELSE 'AFTER_MERGE' END AS MERGE_DAY, D.TOTAL_DEPOSIT, W.TOTAL_WITHDRAW,
    D.TOTAL_DEPOSIT - W.TOTAL_WITHDRAW AS NET_AMOUNT, D.TOTAL_D_HASH, W.TOTAL_W_HASH, D.DEPOSITORS, W.WITHDRAWERS
    FROM DEPOSITOR D
    JOIN WITHDRAW W
    ON D.BLOCK_DAY =W.BLOCK_DAY)

    SELECT *, SUM(TOTAL_DEPOSIT)OVER (ORDER BY BLOCK_DAY) AS OVERALL_DEPOSIT, SUM(TOTAL_WITHDRAW) OVER (ORDER BY BLOCK_DAY)AS OVERALL_WITHDRAW,
    SUM(NET_AMOUNT)OVER (ORDER BY BLOCK_DAY) AS OVERALL_NET, (SELECT SUM(TOTAL_DEPOSIT) FROM M_DETAILS WHERE MERGE_DAY = 'TWOWEEKS_BM') AS TWOWEEKS_BM_DEPOSIT,
    (SELECT SUM(TOTAL_WITHDRAW) FROM M_DETAILS WHERE MERGE_DAY = 'TWOWEEKS_BM') AS TWOWEEEKS_BM_WITHDRAW,
    ((SELECT SUM(TOTAL_DEPOSIT) FROM M_DETAILS WHERE MERGE_DAY = 'TWOWEEKS_BM')/(SELECT SUM(TOTAL_WITHDRAW) FROM M_DETAILS WHERE MERGE_DAY = 'TWOWEEKS_BM')) AS DIFFERENCE
    FROM M_DETAILS
    ORDER BY BLOCK_DAY




    Run a query to Download Data