fix: implement partial_cancel entry point on streaming contract - #696
Merged
Conversation
Adds the partial_cancel contract function referenced by README's function table but never implemented (PartialCancelEvent existed only as dead/undefined intent). Follows the cancel/top_up pattern: the sender reclaims `amount` of the stream's still-locked balance while the stream stays active, re-anchoring the vesting schedule at the current moment (mirroring top_up's re-anchoring in the opposite direction). Adds test_features.rs coverage and emits PartialCancelEvent. Closes FlowwStar#217
christabel888
had a problem deploying
to
staging
August 27, 2026 17:30 — with
GitHub Actions
Failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
partial_cancelwas listed in the README's contract function table ("Sender reduces a stream's locked balance, releasing funds back") but was never actually implemented inimpl StreamingContract— there was no entry point, and noPartialCancelEventtype either. Prior test coverage that referenced it had already been removed fromtest_features.rsin earlier merged PRs, leaving the feature entirely missing.Fix
Implements
partial_cancel(stream_id, amount)incontracts/streaming/src/lib.rs, following the existingcancel/top_uppatterns:require_auth), and only while the contract is unpaused.StreamCancelled/StreamEnded).unlocked_amounthelper;amountmust be> 0and<= locked(InvalidAmountotherwise).amountback to the sender and reducesdeposited_amountby it — the stream is not terminated, unlikecancel.top_upalready does when funds are added): whatever is unlocked as ofnowis frozen as the new "cliff", and the reduced remaining balance streams linearly toend_timeat a recomputed rate (RateIsZeroif that rate would round to zero).PartialCancelEvent(stream_id, sender, recipient, amount_refunded, new_deposited_amount, timestamp), published on success.Also adds test coverage in
contracts/streaming/src/test_features.rs:test_partial_cancel_returns_locked_funds_and_keeps_stream_active— happy path, confirms the stream stays active, deposited amount drops by the refund, already-unlocked funds are untouched, and the stream keeps streaming afterward.test_partial_cancel_rejects_amount_exceeding_locked_balance— over-withdrawal guard.test_partial_cancel_rejects_already_cancelled_stream— guard against calling on a fully-cancelled stream.Notes / TODOs
cargo test/cargo buildin this environment — implementation and tests were written directly from readingcancel/top_upand the existing test harness conventions intest_features.rs. Please run the test suite in CI/locally before merge.docs/api-reference.mddoes not yet have apartial_cancelsection (unlikecancel/top_up/etc.) — left out of scope here since the issue only pointed atlib.rsandtest_features.rs, but worth a follow-up doc PR.lib/contract.ts, hooks) wiring was added — issue scope was the contract entry point itself.Closes #217