Sandeshdex liquidity pool
    Updated 2025-01-13
    /*
    Description:
    This query analyzes token activity across Arbitrum and Ethereum chains for a specific token.
    It calculates liquidity, volume metrics, and identifies liquidity pools for each DEX platform.
    The query uses Common Table Expressions (CTEs) to organize complex logic and improve readability.

    Key features:
    1. Multi-chain analysis (Arbitrum and Ethereum)
    2. Volume calculations for different time periods (7-day, 1-month, total)
    3. Liquidity pool identification and balance calculation
    4. Platform-specific aggregations


    All thanks to andrew hong for the query.
    */

    -- Arbitrum Chain Analysis
    WITH arbitrum AS (
    -- DEX Pool Identification and Volume Calculation
    WITH dex_pools AS (
    SELECT
    platform,
    contract_address AS liquidity_pools,
    -- Calculate volume for different time periods using CASE statements
    SUM(CASE
    WHEN (block_timestamp > current_timestamp - INTERVAL '7 days')
    THEN COALESCE(amount_in_usd, amount_out_usd)
    ELSE NULL
    END) AS seven_day_volume,
    SUM(CASE
    WHEN (block_timestamp > current_timestamp - INTERVAL '1 month')
    THEN COALESCE(amount_in_usd, amount_out_usd)
    ELSE NULL
    END) AS one_month_volume,
    SUM(COALESCE(amount_in_usd, amount_out_usd)) AS total_volume,
    count (distinct (CASE
    Last run: 3 months ago
    CHAIN
    PLATFORM
    TOTAL_LIQUIDITY
    SEVEN_DAY_VOLUME
    ONE_MONTH_VOLUME
    TOTAL_VOLUME
    MONTHLY_USER
    POOL_ADDRESSES
    1
    arbitrumuniswap-v34687857.28850644264391.121437008.0111032860.0828
    [ "0xf5a43fcee8e1892f1d4c8961fabcd1e461886fba", "0xc6a43433bce7f2f9fa42a88335d714a455a5b18d", "0x9b3c84ff3c4fbda53a244e95c9b7b321248b086f", "0x7dfae4316f3e5758863a056b5b4c8be63c69915e", "0xf72f9723b0ef52408e59a482a1d25c3c5ed48918" ]
    2
    ethereumuniswap-v33516308.83728503138381.24478121.1410079701.7733
    [ "0xce56d0f48ca5990d84eb1b76e1aad6f79829c305" ]
    3
    baseuniswap-v33633583.04155387143103.73686708.032731280.2688
    [ "0xd8582fc6daf45ed8076292e7a8586e87fd67bc0c" ]
    4
    baseuniswap-v21541329.57580483148719.17783672.361058778.9382
    [ "0xa754f8b0e4b9b8f8e78ea4b1ca252cc33a6d9606" ]
    5
    arbitrumwoofi0001337.910
    [ "0x4c4af8dbc524681930a27b2f1af5bcc8062e6fb7" ]
    5
    756B
    72s