Hessishthorxdefi - Liquidity Volume tot
    Updated 2024-12-15
    -- forked from thorxdefi - Weekly Liquidity Volume @ https://flipsidecrypto.xyz/edit/queries/5fc49d39-1c8c-4cf3-9249-9de41fcd37a5

    -- forked from hess / Weekly Liquidity Volume @ https://flipsidecrypto.xyz/hess/q/HJ_DXSY20rs9/weekly-liquidity-volume

    with tb1 as ( select block_timestamp,
    tx_id,
    blockchain,
    pool_name,
    ifnull(from_address,native_to_address) as trader,
    from_asset,
    to_asset,
    case when from_amount_usd >= to_amount_usd then to_amount_usd else from_amount_usd end as amount1,
    case when from_amount_usd is null then to_amount_usd else from_amount_usd end as amount2,
    case when amount1 is null then amount2 else amount1 end as amount
    from thorchain.defi.fact_swaps
    where --block_timestamp::date >= '2024-01-01' and
    affiliate_address = 'xdf'
    ),

    liquidity as (select block_timestamp,
    lp_action,
    pool_name,
    ifnull(from_address,ASSET_ADDRESS) as user,
    rune_amount_usd,
    asset_amount_usd,
    rune_amount_usd+asset_amount_usd as amount_usd
    from thorchain.defi.fact_liquidity_actions
    where block_timestamp::date >= '2022-01-01'
    ),

    x as (SELECT
    count(DISTINCT user) as users,
    sum(amount_usd) as volume,
    count(*) as liquidity_tx,
    'Deposits' as type
    Last run: 2 months agoAuto-refreshes every 24 hours
    USERS
    VOLUME
    LIQUIDITY_TX
    TYPE
    1
    1922490571.865176674064Deposits
    2
    2964281180.19303996960Widthrawals
    2
    81B
    241s