Feat/withdraw all - #63
Merged
elizabetheonoja-art merged 2 commits intoMar 24, 2026
Merged
Conversation
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
|
@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! 🚀 |
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.
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
CreatorSubscribers(Address)variant toDataKey— maintains a per-creator index of active subscriber addresses in persistent storagesubscribe()now registers the subscriber into the creator's index on stream creationcancel()removes the subscriber from the creator's index on teardownwithdraw_all(creator, max_count)iterates up tomax_countstreams, accumulates all claimable amounts, then executes one token transfertest_withdraw_allcovering 3 concurrent streams with correct balance assertionsGas Safety
max_countis a deliberate guard against Soroban instruction limits. For large subscriber sets, callers paginate by invokingwithdraw_allrepeatedly with a safe batch size (e.g. 100) rather than processing all subscribers in one transaction.Testing
All existing tests pass. New
test_withdraw_allverifies correct aggregation and single-transfer behavior across multiple streams.