0xHaM-dMonthly Net copy
    Updated 2024-07-21
    -- forked from hess / Monthly Net @ https://flipsidecrypto.xyz/hess/q/XtRjQacFzGyg/monthly-net

    with delegate as (
    select
    trunc(block_timestamp,'week') as weekly,
    sum(amount/pow(10,6)) as delegate_amount,
    sum(delegate_amount) over (order by weekly asc) as cumulative_delegate_amount,
    count(DISTINCT tx_id) as delegate_tx,
    count(DISTINCT DELEGATOR_ADDRESS) as delegate_user,
    avg(amount/pow(10,6)) as avg_delegate_amount
    from axelar.gov.fact_staking
    where action = 'delegate'
    AND block_timestamp < trunc(current_date,'week')
    group by 1
    )
    ,
    undelegate as (
    select
    trunc(block_timestamp,'week') as weekly,
    sum(amount/pow(10,6))*-1 as undelegate_amount,
    sum(undelegate_amount) over (order by weekly asc) as cumulative_undelegate_amount,
    count(DISTINCT tx_id)*-1 as undelegate_tx,
    count(DISTINCT DELEGATOR_ADDRESS)*-1 as undelegate_user,
    avg(amount/pow(10,6)) as avg_undelegate_amount
    from axelar.gov.fact_staking
    where action = 'undelegate'
    AND block_timestamp < trunc(current_date,'week')
    group by 1
    )

    select
    a.weekly,
    delegate_amount,
    undelegate_amount,
    cumulative_delegate_amount,
    cumulative_undelegate_amount,
    QueryRunArchived: QueryRun has been archived