hessTotal II
    Updated 2024-06-06
    -- forked from Total @ https://flipsidecrypto.xyz/edit/queries/e4e39f79-cad1-4ee9-9e59-e731b3e3be76

    with 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 >= '2024-01-01')
    ,
    provide as ( select
    count(DISTINCT user) as delegators,
    sum(amount_usd) as add_volume,
    count(*) as add_liquidity_tx
    from liquidity
    where lp_action = 'add_liquidity'
    )
    ,
    remove as ( select
    count(DISTINCT user)*-1 as undelegators,
    sum(amount_usd)*-1 as remove_volume,
    count(*)*-1 as remove_liquidity_tx
    from liquidity
    where lp_action = 'remove_liquidity'

    )


    select undelegators, delegators,
    add_liquidity_tx, remove_liquidity_tx
    from provide , remove
    QueryRunArchived: QueryRun has been archived