Skip to content

feat(contracts): add cross-asset swap deposit to payment-stream (#508) - #551

Merged
Idrhas merged 2 commits into
Fundable-Protocol:mainfrom
damiedee96:feat/508-cross-asset-swap-deposit
Aug 3, 2026
Merged

feat(contracts): add cross-asset swap deposit to payment-stream (#508)#551
Idrhas merged 2 commits into
Fundable-Protocol:mainfrom
damiedee96:feat/508-cross-asset-swap-deposit

Conversation

@damiedee96

@damiedee96 damiedee96 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor
  • 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)

closes #508

Summary by CodeRabbit

  • New Features
    • Added support for depositing into payment streams by swapping from another asset through a configured DEX.
    • Added slippage protection and stream-capacity validation for swap-based deposits.
    • Added administrator controls to configure and retrieve the DEX router.
    • Added events to provide visibility into swap-based deposits and received amounts.

…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)
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e0e5617-e3a9-461c-a23c-173b694ac176

📥 Commits

Reviewing files that changed from the base of the PR and between b78e128 and f16a04b.

📒 Files selected for processing (1)
  • contracts/payment-stream/src/lib.rs

📝 Walkthrough

Walkthrough

The 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.

Changes

Cross-Asset Stream Deposits

Layer / File(s) Summary
Swap deposit event contract
contracts/payment-stream/src/lib.rs
Adds the public SwapDepositEvent payload for stream ID, source token, input amount, and output amount.
DEX router configuration
contracts/payment-stream/src/lib.rs
Adds admin router registration with persistent storage and a getter for the configured router.
Cross-asset deposit flow
contracts/payment-stream/src/lib.rs
Adds authorization, swap-path construction, token transfer, router execution, output validation, stream updates, metrics, and SwapDeposit and StreamDeposit events.

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
Loading

Possibly related PRs

Suggested reviewers: fayedamz

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive Core swap-deposit logic, auth, errors, and tests are present, but TTL/docs/clean-build requirements can't be verified from the summary. Provide evidence or code for TTL management, public API docs, and clean wasm/test runs.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding cross-asset swap deposits to payment-stream.
Out of Scope Changes check ✅ Passed The summary stays focused on swap-deposit functionality and supporting tests, with no unrelated feature work apparent.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
contracts/payment-stream/src/test.rs (1)

1888-2106: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Test coverage gaps: SlippageExceeded and SwapFailed paths untested.

None of the ten new tests exercise the contract's own Error::SlippageExceeded (#18) check — MockDexRouter already panics on its own slippage failure before the contract's balance-delta check can trigger — nor Error::SwapFailed (#19) for the "no router configured" path (every test calls set_dex_router first). Multi-hop swap_path construction is also untested (all tests pass an empty path).

Consider adding:

  • A test that skips set_dex_router and 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_out guard.
🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 375c936 and b78e128.

📒 Files selected for processing (2)
  • contracts/payment-stream/src/lib.rs
  • contracts/payment-stream/src/test.rs

Comment thread contracts/payment-stream/src/lib.rs
Comment thread contracts/payment-stream/src/test.rs Outdated
@Idrhas

Idrhas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates

@Idrhas

Idrhas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates

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.

[Contract] Support Cross-Asset Liquidity Swaps on Stream Deposit Invocations

2 participants