banbannardcsMATIC Net Staked
    Updated 2022-09-20
    with base as (select date_trunc('day', block_timestamp) as day,
    count(distinct(matic_from_address)) as count_staker,
    sum(amount) as matic_staked,
    sum(matic_staked) over (order by day) as cum_matic_staked,
    count(distinct(tx_hash)) as tx_count
    from polygon.core.ez_matic_transfers
    where --tx_hash ='0xa61984fe44ca36804e00f88672ebf413e0f35d7525fb0682caf7ec121049d7db'
    matic_to_address = '0x376b467dff007dd8d3f24404caddff7f72257fe4'
    and origin_to_address = '0x376b467dff007dd8d3f24404caddff7f72257fe4'
    and origin_function_signature = '0xd0e30db0'
    group by 1),

    base2 as (select date_trunc('day', block_timestamp) as day,
    count(distinct(origin_from_address)) as count_unstaker,
    sum(amount) as matic_unstaked,
    sum(matic_unstaked) over (order by day) as cum_matic_unstaked,
    count(distinct(tx_hash)) as tx_count
    from polygon.core.ez_matic_transfers
    where --tx_hash ='0xa61984fe44ca36804e00f88672ebf413e0f35d7525fb0682caf7ec121049d7db'
    matic_from_address = '0x376b467dff007dd8d3f24404caddff7f72257fe4'
    and origin_to_address = '0x376b467dff007dd8d3f24404caddff7f72257fe4'
    and origin_function_signature = '0xfd92bff2'
    group by 1)

    select a.day,
    cum_matic_staked - cum_matic_unstaked as net_matic_staked
    from base a
    join base2 b
    on a.day = b.day
    Run a query to Download Data