flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Contracts] Settle accrued amounts before modify_rate moves the accrual anchor

Open blurbeast opened this issue 2 weeks ago • 4 comments

Overview & Background

modify_rate sets stream.rate_per_second = new_rate_per_second; stream.last_update_time = now; with no settlement of accrued amounts — directly contradicting the rationale documented in top_up_stream: "last_update_time is intentionally left untouched: it is the accrual anchor for calculate_claimable, and advancing it to now would discard any already-vested, unwithdrawn tokens." Anything vested but unclaimed at the moment of the rate change is folded back into the unstreamed remainder, so the recipient must wait for the new rate to re-accrue tokens that were already theirs. A sender can call modify_rate with rate 1 to arbitrarily defer vested wages. No test checks claimable continuity across the change.


Technical Specification & Architecture

  1. In contracts/stream_contract/src/lib.rs:2768-2769, settle (withdraw or credit) the claimable amount before moving last_update_time, mirroring transfer_recipient's settle-then-handover flow (lib.rs:788-796).
  2. Add tests asserting claimable continuity: tokens vested before the rate change remain claimable after it.

Target Files

  • contracts/stream_contract/src/lib.rs
  • contracts/stream_contract/src/test.rs

Acceptance Criteria

  • [ ] Vested-but-unclaimed tokens are not re-locked by a rate change.
  • [ ] calculate_claimable is continuous across modify_rate.
  • [ ] Tests cover rate increase, decrease, and the rate-1 deflation attack.

blurbeast avatar Nov 18 '26 19:11 blurbeast

@Kami-no-san has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

Hi Maintainer,

I’d like to take this on. I will update modify_rate in contracts/stream_contract/src/lib.rs to settle accrued claimable tokens before advancing last_update_time (following the settle-then-handover pattern in transfer_recipient so vested amounts aren't re-locked), and add tests in contracts/stream_contract/src/test.rs verifying calculate_claimable continuity across rate increases, decreases, and rate-1 deflation attempts.

ℹ️ Repo Maintainers: To accept this application, review their application or assign @Kami-no-san to this issue.

Kami-no-san avatar Nov 20 '26 20:11 Kami-no-san

@king-daveed has applied to work on this issue as part of the Stellar Wave Program's 11th wave.

i can resolve

ℹ️ Repo Maintainers: To accept this application, review their application or assign @king-daveed to this issue.

king-daveed avatar Nov 21 '26 08:11 king-daveed

Congratulations, @king-daveed! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.

🧑‍💻 @king-daveed: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

🌊 Happy Wave 🌊

drips-wave[bot] avatar Nov 21 '26 08:11 drips-wave[bot]

This issue has been completed by @king-daveed as part of the Stellar Wave Program's 11th Wave 🥳

😎 @king-daveed: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

drips-wave[bot] avatar Nov 24 '26 17:11 drips-wave[bot]