Skip to content

Feat/withdraw all - #63

Merged
elizabetheonoja-art merged 2 commits into
SubStream-Protocol:mainfrom
Hahfyeex:feat/withdraw-all
Mar 24, 2026
Merged

Feat/withdraw all#63
elizabetheonoja-art merged 2 commits into
SubStream-Protocol:mainfrom
Hahfyeex:feat/withdraw-all

Conversation

@Hahfyeex

Copy link
Copy Markdown
Contributor

this pr closes #3

Problem

Creators with large subscriber bases had no way to collect earnings in bulk. Calling collect() individually for each subscriber is impractical at scale — a creator with 1,000 subscribers would need 1,000 separate transactions.

Solution

Introduces withdraw_all(creator, max_count) which lets a creator drain all active streams in a single call, with a single token transfer to their address.

Changes

  • Added CreatorSubscribers(Address) variant to DataKey — maintains a per-creator index of active subscriber addresses in persistent storage
  • subscribe() now registers the subscriber into the creator's index on stream creation
  • cancel() removes the subscriber from the creator's index on teardown
  • withdraw_all(creator, max_count) iterates up to max_count streams, accumulates all claimable amounts, then executes one token transfer
  • Added test_withdraw_all covering 3 concurrent streams with correct balance assertions

Gas Safety

max_count is a deliberate guard against Soroban instruction limits. For large subscriber sets, callers paginate by invoking withdraw_all repeatedly with a safe batch size (e.g. 100) rather than processing all subscribers in one transaction.

Testing

All existing tests pass. New test_withdraw_all verifies correct aggregation and single-transfer behavior across multiple streams.

Creators with many subscribers previously had to call collect() once
per subscriber. This adds withdraw_all() which:

- Maintains a CreatorSubscribers index in persistent storage so all
  active subscriber addresses are discoverable per creator
- Iterates up to max_count streams, accumulates claimable amounts,
  then executes a single token transfer to the creator
- max_count guards against hitting Soroban instruction limits on large
  subscriber sets — callers can paginate by calling repeatedly
- subscribe() registers the subscriber in the creator index
- cancel() removes the subscriber from the creator index on teardown
- Includes test_withdraw_all covering 3 concurrent streams

Closes: withdraw_all optimization issue
@drips-wave

drips-wave Bot commented Mar 24, 2026

Copy link
Copy Markdown

@Hahfyeex Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@elizabetheonoja-art
elizabetheonoja-art merged commit f7d030b into SubStream-Protocol:main Mar 24, 2026
1 check failed
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.

#3 Issue: [Optimization] Batch Withdraw for Creators

2 participants