flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[Contracts] Fix hybrid-cliff tail rate computed from the wrong amount

Open blurbeast opened this issue 1 week ago • 5 comments

Overview & Background

In create_hybrid_cliff_stream, the linear tail rate is computed as let linear_amount = net_amount - total_fee; — but net_amount is already the post-fee deposit (collect_fee defines net_amount = amount - total_fee). This double-deducts the fee and, worse, never subtracts cliff_unlock_amount. The doc comment and error docs both state the correct formula: (net - cliff) / linear_duration. With no fee configured the tail rate becomes net / duration instead of (net - cliff) / duration, so the drip pace and the emitted rate_per_second/end-time are materially wrong. The bug is masked by integer-division coincidences in tests (1000/400-cliff/600s gives 1/s under both formulas).


Technical Specification & Architecture

  1. In contracts/stream_contract/src/lib.rs:1205-1206, change to let linear_amount = net_amount - cliff_unlock_amount;.
  2. Add a hybrid-cliff test with a non-divisible amount (e.g. 1000, cliff 200, duration 80) that asserts an intermediate claimable to lock the 10/s rate.
  3. Enable protocol fees in at least one hybrid-cliff test — the current suite never does, which is what hides this bug.

Target Files

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

Acceptance Criteria

  • [ ] Tail rate equals (net_amount - cliff_unlock_amount) / linear_duration.
  • [ ] A fee-enabled hybrid-cliff test asserts an intermediate claimable amount.
  • [ ] Emitted rate_per_second and projected end time match the documented formula.

blurbeast avatar Nov 18 '26 19:11 blurbeast

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

Hello maintainer, I would love to solve this pls assign

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

SahheedTech avatar Nov 20 '26 22:11 SahheedTech

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

i can do it

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

wagmiiii avatar Nov 21 '26 07:11 wagmiiii

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

🧑‍💻 @wagmiiii: 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 07:11 drips-wave[bot]

🎉 This issue has been marked as completed on GrantFox!

@wagmiiii's PR #1941 was approved and merged by @K1NGD4VID.

🏆 @wagmiiii: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,665 total points). Track your full progress on GrantFox.

👏 Great work, @wagmiiii! Keep contributing to LabsCrypt.

grantfox-oss[bot] avatar Nov 21 '26 17:11 grantfox-oss[bot]

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

😎 @wagmiiii: 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 21 '26 17:11 drips-wave[bot]