Skip to content

Conversation

@arad-starkware
Copy link
Collaborator

@arad-starkware arad-starkware commented Nov 25, 2025

This change is Reviewable


Note

Adds a new BalancesDelayFlow and mainnet fork test to verify staking power and STRK/BTC rewards timing across epochs pre/post-upgrade.

  • Flows (src/flow_test/flows.cairo):
    • BalancesDelayFlow: New flow exercising delayed balance effects across epochs and an upgrade.
      • Sets up staker, STRK and BTC delegators; performs stake/delegate increases; triggers upgrade; and asserts:
        • Total staking power per epoch (Epoch 0 baseline; Epoch 1 pre-/post-upgrade).
        • Staker rewards via attestations and delegator rewards (STRK/BTC) across Epochs 1–4.
  • Tests (src/flow_test/fork_test.cairo):
    • Adds balances_delay_flow_test (MAINNET_LATEST) to run the new flow.

Written by Cursor Bugbot for commit 5f4a056. This will update automatically on new commits. Configure here.

Copy link
Collaborator Author

arad-starkware commented Nov 25, 2025

@arad-starkware arad-starkware marked this pull request as ready for review November 25, 2025 13:29
Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 5 unresolved discussions (waiting on @arad-starkware)


src/flow_test/flows.cairo line 7147 at r1 (raw file):

/// Flow:
/// Epoch 0:
///     Staker stake

why not delegators enter here and increase later?


src/flow_test/flows.cairo line 7155 at r1 (raw file):

///     Delegators increase delegation STRK and BTC
///     Test total staking power - according to Epoch 0
///     Test staker balance with attestation rewards - according to Epoch 0

maybe use actual numbers or x,y,... to make it clearer?

Code quote:

 according to Epoch 0

src/flow_test/flows.cairo line 7170 at r1 (raw file):

    pub(crate) staker: Option<Staker>,
    pub(crate) stake_amount: Option<Amount>,
    pub(crate) commission: Option<Commission>,

You can get that from staker_info after upgrade instead of saving it

Code quote:

    pub(crate) commission: Option<Commission>,

src/flow_test/flows.cairo line 7343 at r1 (raw file):

        let staker_stake = stake_amount * 3;
        let strk_pool_balance = strk_delegated_amount * 2;
        let btc_pool_balance = btc_delegated_amount * 2;

Suggestion:

        let staker_stake = staker_stake + stake_amount;
        let strk_pool_balance = strk_pool_balance * 2;
        let btc_pool_balance = btc_pool_balance * 2;

src/flow_test/flows.cairo line 7375 at r1 (raw file):

        );
        assert!(expected_btc_commission_rewards.is_non_zero());
        assert!(expected_btc_pool_rewards.is_non_zero());

assert rewards are not equal to prev rewards?

Code quote:

        assert!(expected_staker_rewards.is_non_zero());
        assert!(expected_strk_pool_rewards.is_non_zero());
        let (expected_btc_commission_rewards, expected_btc_pool_rewards) =
            calculate_staker_btc_pool_rewards_v2(
            pool_balance: btc_pool_balance,
            :commission,
            :staking_contract,
            :minting_curve_contract,
            token_address: system.btc_token.contract_address(),
        );
        assert!(expected_btc_commission_rewards.is_non_zero());
        assert!(expected_btc_pool_rewards.is_non_zero());

@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch from e4e94f2 to 33b6d35 Compare November 25, 2025 15:14
@arad-starkware arad-starkware changed the base branch from arad/chore_update_flow_ideas to graphite-base/65 November 25, 2025 15:32
@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch from 33b6d35 to bfc06f8 Compare November 25, 2025 15:34
@arad-starkware arad-starkware changed the base branch from graphite-base/65 to arad/chore_update_flow_ideas November 25, 2025 15:34
@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch 3 times, most recently from 8a264ba to 4c26f6d Compare November 25, 2025 16:06
Copy link
Collaborator Author

@arad-starkware arad-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @arad-starkware and @noa-starkware)


src/flow_test/flows.cairo line 7147 at r1 (raw file):

Previously, noa-starkware wrote…

why not delegators enter here and increase later?

Why yes?
The staker does it because we can't attest unless an epoch has passed since the initial stake, but there's no such limitation on the delegators.


src/flow_test/flows.cairo line 7155 at r1 (raw file):

Previously, noa-starkware wrote…

maybe use actual numbers or x,y,... to make it clearer?

wdym?


src/flow_test/flows.cairo line 7170 at r1 (raw file):

Previously, noa-starkware wrote…

You can get that from staker_info after upgrade instead of saving it

Technically I can infer everything here from the staker address and the view functions, why draw the line at commission?


src/flow_test/flows.cairo line 7375 at r1 (raw file):

Previously, noa-starkware wrote…

assert rewards are not equal to prev rewards?

Done


src/flow_test/flows.cairo line 7343 at r1 (raw file):

        let staker_stake = stake_amount * 3;
        let strk_pool_balance = strk_delegated_amount * 2;
        let btc_pool_balance = btc_delegated_amount * 2;

Done

Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @arad-starkware)


src/flow_test/flows.cairo line 7375 at r1 (raw file):

Previously, arad-starkware wrote…

Done

Why bigger?

@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch from 4c26f6d to 85b9981 Compare November 26, 2025 08:01
@arad-starkware arad-starkware force-pushed the arad/chore_update_flow_ideas branch from 631614f to a1ef5f2 Compare November 26, 2025 08:01
@arad-starkware arad-starkware changed the base branch from arad/chore_update_flow_ideas to graphite-base/65 November 26, 2025 08:04
@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch from 85b9981 to 9ce74b6 Compare November 26, 2025 08:05
@graphite-app graphite-app bot changed the base branch from graphite-base/65 to main November 26, 2025 08:05
@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch from 9ce74b6 to 1204107 Compare November 26, 2025 08:05
@codecov
Copy link

codecov bot commented Nov 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.60%. Comparing base (fdd38dd) to head (5f4a056).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #65   +/-   ##
=======================================
  Coverage   95.60%   95.60%           
=======================================
  Files          42       42           
  Lines        9754     9754           
=======================================
  Hits         9325     9325           
  Misses        429      429           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator Author

@arad-starkware arad-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @noa-starkware)


src/flow_test/flows.cairo line 7375 at r1 (raw file):

Previously, noa-starkware wrote…

Why bigger?

total supply goes up -> yearly mint goes up -> rewards go up
There are several places where rewards might have gone down though:

  1. Second stake for the staker, since his relative share of the staking power goes down (strk delegator enters).
  2. Subsequent delegations by the strk delegator, since the staker's share grows more than the delegator's share (stake_amount > strk_delegation_amount).
    It seems as though in both cases the increase in total supply causes an increase in rewards that makes up for this though, which is why the test passes.
    Maybe we should only assert different rewards, instead of larger ones, in those cases. WDYT?

@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch 4 times, most recently from c909703 to d3ed532 Compare November 26, 2025 14:21
Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @arad-starkware)


src/flow_test/flows.cairo line 7375 at r1 (raw file):

Previously, arad-starkware wrote…

total supply goes up -> yearly mint goes up -> rewards go up
There are several places where rewards might have gone down though:

  1. Second stake for the staker, since his relative share of the staking power goes down (strk delegator enters).
  2. Subsequent delegations by the strk delegator, since the staker's share grows more than the delegator's share (stake_amount > strk_delegation_amount).
    It seems as though in both cases the increase in total supply causes an increase in rewards that makes up for this though, which is why the test passes.
    Maybe we should only assert different rewards, instead of larger ones, in those cases. WDYT?

I think only assert different rewards is better

Copy link
Collaborator Author

@arad-starkware arad-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @noa-starkware)


src/flow_test/flows.cairo line 7375 at r1 (raw file):

Previously, noa-starkware wrote…

I think only assert different rewards is better

Done

@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch 2 times, most recently from 071a55d to 6ad074b Compare November 26, 2025 17:16
Copy link
Collaborator

@noa-starkware noa-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 3 files reviewed, 3 unresolved discussions (waiting on @arad-starkware)


src/flow_test/flows.cairo line 8676 at r6 (raw file):

        // Test total staking power - according to Epoch 0.
        let staker_stake = stake_amount;

mut and += later


src/flow_test/flows.cairo line 8714 at r6 (raw file):

        let staker_stake = staker_stake + stake_amount;
        let strk_pool_balance = strk_delegated_amount;
        let btc_pool_balance = btc_delegated_amount;

mut and += later

Code quote:

        let strk_pool_balance = strk_delegated_amount;
        let btc_pool_balance = btc_delegated_amount;

@arad-starkware arad-starkware force-pushed the arad/test_add_balances_delay_flow branch from 6ad074b to 5f4a056 Compare November 26, 2025 17:26
@arad-starkware arad-starkware merged commit 3ee5f59 into main Nov 27, 2025
7 of 8 checks passed
Copy link
Collaborator Author

Merge activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants