Skip to content

feat: implement real DEX router integration for swap_and_pay #375

Description

@Pvsaint

Problem

dex_router.rs contains only a stub implementation. Both swap_exact_tokens_for_tokens and swap_tokens_for_exact_tokens are no-ops: they do not transfer tokens, do not enforce slippage, and emit event symbols without actually publishing them. Additionally, SwapAndPayArgs is defined in lib.rs but there is no swap_and_pay entry point on PaymentProcessor.

// Current stub — does nothing
pub fn swap_exact_tokens_for_tokens(...) -> Vec<i128> {
    soroban_sdk::Symbol::new(&env, "SWAP"); // no-op
    ...
}

Required Work

  1. Implement swap_and_pay on PaymentProcessor using SwapAndPayArgs
  2. Call the external DEX router contract via cross-contract invocation using DexRouterClient
  3. Enforce amount_out_min slippage guard — panic/error if output < minimum
  4. Enforce deadline — reject if env.ledger().timestamp() > deadline
  5. After swap succeeds, create the payment via normal create_payment flow
  6. Emit SWAP/EXECUTED event with correct data payload

Acceptance Criteria

  • swap_and_pay is callable on PaymentProcessor and accepts SwapAndPayArgs
  • Token transfer from payer to router is executed via the token contract
  • amount_out_min slippage is enforced; returns InvalidAmount error if violated
  • deadline is enforced; returns PaymentExpired error if past
  • A SWAP/EXECUTED event is emitted with (stream_id, sender, amount_in, amount_out) data
  • Integration test covers: happy path, slippage exceeded, expired deadline
  • EVENTS.md is updated with the SWAP/EXECUTED event definition

Branch & Commit Examples

branch: feat/swap-and-pay
commit: feat(payment-processor): implement swap_and_pay with DEX router integration

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions