Skip to content

feat(stream_contract): give disputes and yield an activation path - #1954

Closed
achiever2110 wants to merge 1 commit into
LabsCrypt:mainfrom
achiever2110:feat/arbiter-activation
Closed

achiever2110 wants to merge 1 commit into
LabsCrypt:mainfrom
achiever2110:feat/arbiter-activation

Conversation

@achiever2110

Copy link
Copy Markdown
Contributor

Closes #1897

What changed

Every stream constructor hardcoded arbiter: None and yield_enabled: false, and no entrypoint ever wrote either field. request_dispute and resolve_dispute therefore always failed with DisputeNotSupported in production, the yield flag could never be turned on, and the tests could only exercise disputes by injecting arbiter straight into storage.

set_stream_arbiter(sender, stream_id, arbiter: Option<Address>)

Sender-authorized, and the only way the arbiter slot is ever written:

  • validates ownership and that the stream is active
  • rejects an arbiter that is the stream's own sender or recipient (a party that benefits from one side cannot arbitrate it)
  • is frozen while a dispute is open, so a pending dispute cannot be re-pointed at a friendlier arbiter
  • emits arbiter_updated with the new value (None clears it)

cancel_stream now rejects streams that have an arbiter configured (ArbiterConfigured, code 50), so the arbiter actually gates unilateral cancellation instead of being a decorative field: the sender must request_dispute and the arbiter must approve it.

set_stream_yield(sender, stream_id, enabled: bool)

Sender-authorized toggle for the per-stream yield opt-in, emitting yield_preference_updated. It records the preference only and deliberately leaves escrow accounting untouched; the YieldStrategy trait remains the adapter surface for a concrete implementation.

Tests

The dispute tests now configure the arbiter through the public entrypoint instead of storage injection, and three new tests cover the whole path end to end:

  • activation → unilateral cancel refused → dispute → non-arbiter refused → arbiter approves and funds split 400/600
  • clearing the arbiter restores unilateral cancellation
  • yield toggle on/off, unauthorized caller refused, event payload, and a cancelled stream rejecting further changes

docs-site/docs/contracts/soroban-reference.md gains the error-table rows for 49 and 50.

Verification

  • cargo test -p stream_contract: 310 passed, 0 failed, 1 pre-existing ignored
  • cargo clippy -p stream_contract --all-targets -- -D warnings: clean

Note: #[contracterror] enums cap out at 50 variants, so the "dispute already open" rejection reports Unauthorized with the documented explanation rather than a 51st variant.

Every stream constructor hardcoded `arbiter: None` and `yield_enabled:
false`, and no entrypoint ever wrote either field, so `request_dispute`
and `resolve_dispute` could only ever fail and the yield opt-in was
permanently dead. Tests reached into storage to seed the arbiter, which
proved the code worked but not that the feature was reachable.

- add `set_stream_arbiter` (sender-only) so the dispute flow is reachable
  through the public API; a dispute freezes the slot, and neither party to
  the stream may arbitrate it
- make `cancel_stream` reject streams with an arbiter configured, so the
  arbiter actually gates unilateral cancellation
- add `set_stream_yield` (sender-only) so the yield opt-in can be turned
  on and off, with an event indexers can follow
- configure the arbiter through the public entrypoint in the dispute tests
  instead of injecting it into storage
@achiever2110

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #1934, which already implements this issue from the same branch owner and is still open. This branch was a second implementation and would only compete with it.

@achiever2110
achiever2110 deleted the feat/arbiter-activation branch November 23, 2026 07:31
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.

[Contracts] Provide an arbiter activation path for the dispute/escrow subsystem

1 participant