[Contracts] Fix withdraw_and_swap double payout and inverted slippage
Overview & Background
withdraw_and_swap first pays the recipient the full claimable principal via apply_withdrawal, then invokes router_client.swap_exact_tokens_for_tokens(&claimable, ...) sourcing amount_in from this contract — with no approve ever issued to the router. Depending on the router this either always reverts (no allowance) or, if any variant can pull, drains other streams' escrowed tokens while the recipient also keeps the principal: a double payout from pooled, multi-stream escrow. The "refund" fallback branch is dead weight (any Err rolls back the transaction anyway), and the emitted "slippage" is computed as min_target_amount - output_amount only when output >= min, so it is always ≤ 0 — an inverted sign.
Technical Specification & Architecture
- Route the claimable amount to the router (or approve it) instead of paying the recipient first; the recipient should receive the swap output (or the original amount on swap failure, via proper flow design).
- Delete the misleading "refund" branch in
contracts/stream_contract/src/lib.rs:2228-2231in favor of transaction rollback semantics. - Emit
output - min_target_amount(or expected-vs-actual delta) as slippage (lib.rs:2245). - Add tests covering swap success, swap failure (rollback), and escrow isolation from other streams.
Target Files
contracts/stream_contract/src/lib.rscontracts/stream_contract/src/test.rs
Acceptance Criteria
- [ ] A successful
withdraw_and_swappays out exactly once (swap output, not principal + swap). - [ ] Other streams' escrowed balances are never sourced for a swap.
- [ ] Slippage field has a non-negative, meaningful value.
- [ ] Swap failure reverts cleanly with no state mutation.
@Sharon-dev-create has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
I am a web 3 full-stack and smart contract developer, and this fix aligns with my expertise. Kindly assign the issue to me.
ℹ️ Repo Maintainers: To accept this application, review their application or assign @Sharon-dev-create to this issue.
@wagmiiii has applied to work on this issue as part of the Stellar Wave Program's 11th wave.
i can handle this ser
ℹ️ Repo Maintainers: To accept this application, review their application or assign @wagmiiii to this issue.
Congratulations, @wagmiiii! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on November 25, 2026.
🧑💻 @wagmiiii: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.
[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.
🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.
🌊 Happy Wave 🌊
This issue has been completed by @wagmiiii as part of the Stellar Wave Program's 11th Wave 🥳
😎 @wagmiiii: You earned 200 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.
🧑💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.