Skip to content

fix: implement partial_cancel entry point on streaming contract - #696

Merged
Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
christabel888:fix/issue-217
Aug 27, 2026
Merged

fix: implement partial_cancel entry point on streaming contract#696
Austinaminu2 merged 1 commit into
FlowwStar:mainfrom
christabel888:fix/issue-217

Conversation

@christabel888

Copy link
Copy Markdown

Problem

partial_cancel was listed in the README's contract function table ("Sender reduces a stream's locked balance, releasing funds back") but was never actually implemented in impl StreamingContract — there was no entry point, and no PartialCancelEvent type either. Prior test coverage that referenced it had already been removed from test_features.rs in earlier merged PRs, leaving the feature entirely missing.

Fix

Implements partial_cancel(stream_id, amount) in contracts/streaming/src/lib.rs, following the existing cancel/top_up patterns:

  • Only the stream's sender may call it (require_auth), and only while the contract is unpaused.
  • Rejects an already-cancelled or already-ended stream (StreamCancelled / StreamEnded).
  • Computes the currently unlocked vs. locked balance via the existing unlocked_amount helper; amount must be > 0 and <= locked (InvalidAmount otherwise).
  • Transfers amount back to the sender and reduces deposited_amount by it — the stream is not terminated, unlike cancel.
  • Re-anchors the vesting schedule at the current moment (the mirror image of what top_up already does when funds are added): whatever is unlocked as of now is frozen as the new "cliff", and the reduced remaining balance streams linearly to end_time at a recomputed rate (RateIsZero if that rate would round to zero).
  • Adds a new 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

  • Not run through cargo test/cargo build in this environment — implementation and tests were written directly from reading cancel/top_up and the existing test harness conventions in test_features.rs. Please run the test suite in CI/locally before merge.
  • docs/api-reference.md does not yet have a partial_cancel section (unlike cancel/top_up/etc.) — left out of scope here since the issue only pointed at lib.rs and test_features.rs, but worth a follow-up doc PR.
  • No frontend (lib/contract.ts, hooks) wiring was added — issue scope was the contract entry point itself.

Closes #217

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
@Austinaminu2
Austinaminu2 merged commit 8216854 into FlowwStar:main Aug 27, 2026
1 of 7 checks passed
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.

bug: partial_cancel called throughout tests but never implemented in the contract

3 participants