feat(contracts): add cross-asset swap deposit to payment-stream (#508) - #551
Conversation
…able-Protocol#508) - Add DexRouter trait with contractclient macro for cross-contract DEX calls - Add deposit_with_swap() function for atomic XLM->USDC-style stream deposits - Add set_dex_router() / get_dex_router() admin functions - Add SwapDepositEvent struct for indexer compatibility - Add 3 new Error variants: InvalidSwapPath(17), SlippageExceeded(18), SwapFailed(19) - Add 10 comprehensive unit tests with MockDexRouter (success, edge cases, failures)
|
@damiedee96 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! 🚀 |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe payment stream contract now supports cross-asset deposits through a configured DEX router. It validates swaps, updates stream state and metrics, emits deposit events, and exposes router configuration methods. ChangesCross-Asset Stream Deposits
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant StreamSender
participant PaymentStreamContract
participant SourceToken
participant ConfiguredDexRouter
participant StreamToken
StreamSender->>PaymentStreamContract: deposit_with_swap(...)
PaymentStreamContract->>SourceToken: Transfer source amount
PaymentStreamContract->>ConfiguredDexRouter: Execute swap path
ConfiguredDexRouter->>StreamToken: Deliver swapped tokens
PaymentStreamContract->>PaymentStreamContract: Validate output and update stream
PaymentStreamContract-->>StreamSender: Emit deposit events
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
contracts/payment-stream/src/test.rs (1)
1888-2106: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winTest coverage gaps:
SlippageExceededandSwapFailedpaths untested.None of the ten new tests exercise the contract's own
Error::SlippageExceeded(#18) check —MockDexRouteralready panics on its own slippage failure before the contract's balance-delta check can trigger — norError::SwapFailed(#19) for the "no router configured" path (every test callsset_dex_routerfirst). Multi-hopswap_pathconstruction is also untested (all tests pass an empty path).Consider adding:
- A test that skips
set_dex_routerand asserts#[should_panic(expected = "Error(Contract,#19)")].- A mock router variant that under-delivers output without self-panicking, to exercise the contract's own
actual_received < min_amount_outguard.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@contracts/payment-stream/src/test.rs` around lines 1888 - 2106, Expand the deposit_with_swap tests around test_deposit_with_swap_success to cover the missing branches: add a no-router case that omits set_dex_router and expects Error(Contract, `#19`), and use a non-panicking mock router variant that under-delivers output to trigger the contract’s own Error(Contract, `#18`) slippage check. Also add a multi-hop case with a populated swap_path, verifying the swap succeeds and preserves the expected balance behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@contracts/payment-stream/src/lib.rs`:
- Around line 469-475: Update the output validation near reported_out so the
router-reported final amount is actually compared against actual_received,
rejecting mismatches through the existing error path. Remove the let _ discard
and misleading comment, while preserving the existing min_amount_out slippage
check.
In `@contracts/payment-stream/src/test.rs`:
- Around line 1832-1839: Restore the module declaration by placing mod mock_dex
{ on its own line after the banner comment. Ensure the MockDexRouter definitions
and related impl remain inside mock_dex so the later use mock_dex::MockDexRouter
and mod test structure compile correctly.
---
Nitpick comments:
In `@contracts/payment-stream/src/test.rs`:
- Around line 1888-2106: Expand the deposit_with_swap tests around
test_deposit_with_swap_success to cover the missing branches: add a no-router
case that omits set_dex_router and expects Error(Contract, `#19`), and use a
non-panicking mock router variant that under-delivers output to trigger the
contract’s own Error(Contract, `#18`) slippage check. Also add a multi-hop case
with a populated swap_path, verifying the swap succeeds and preserves the
expected balance behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: ad09a69a-6b36-456f-8329-9bf608a8ebac
📒 Files selected for processing (2)
contracts/payment-stream/src/lib.rscontracts/payment-stream/src/test.rs
|
dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates |
|
dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates |
closes #508
Summary by CodeRabbit