princefarzamFlow staking
    Updated 2022-11-16
    WITH Staking AS (
    SELECT
    date_trunc('day',BLOCK_TIMESTAMP) AS DAY,
    sum(AMOUNT) AS Staked_FLOW_Volume
    FROM flow.core.ez_staking_actions
    WHERE ACTION IN ('DelegatorTokensCommitted','TokensCommitted')
    AND TX_SUCCEEDED = TRUE
    AND BLOCK_TIMESTAMP BETWEEN '2022-11-07'and '2022-11-14'
    GROUP BY DAY
    ORDER BY DAY),
    Unstaking AS(
    SELECT
    date_trunc('day',BLOCK_TIMESTAMP) AS DAY,
    sum(AMOUNT) AS Unstaked_FLOW_Volume
    FROM flow.core.ez_staking_actions
    WHERE ACTION IN ('UnstakedTokensWithdrawn', 'DelegatorUnstakedTokensWithdrawn' , 'DelegatorRewardTokensWithdrawn', 'RewardTokensWithdrawn')
    AND TX_SUCCEEDED = TRUE
    AND BLOCK_TIMESTAMP BETWEEN '2022-11-07'and '2022-11-14'
    GROUP BY DAY
    ORDER BY DAY)
    SELECT
    S.DAY,
    Staked_FLOW_Volume,
    -Unstaked_FLOW_Volume,
    Staked_FLOW_Volume - Unstaked_FLOW_Volume AS Net_Staked_Amount
    FROM Staking S LEFT JOIN Unstaking U on S.DAY=U.DAY