Skip to content

feat(soroban): on-chain contribution router with slippage enforcement…#75

Open
cybermax4200 wants to merge 18 commits into
Savitura:mainfrom
cybermax4200:feat/soroban-contribution-router
Open

feat(soroban): on-chain contribution router with slippage enforcement…#75
cybermax4200 wants to merge 18 commits into
Savitura:mainfrom
cybermax4200:feat/soroban-contribution-router

Conversation

@cybermax4200
Copy link
Copy Markdown
Contributor

Closes #60

What changed

contracts/soroban/contracts/router/ (new)

  • route_contribution(sender, send_asset, send_max, dest_asset, dest_amount, path, campaign_wallet, platform_wallet, fee_bps, max_slippage_bps)
  • Slippage ceiling enforced on-chain:
    send_max <= dest_amount * (10_000 + max_slippage_bps) / 10_000 — panics if exceeded
  • Atomic fee split: campaign receives dest_amount * (10_000 - fee_bps) / 10_000,
    platform receives fee_amount — both in the same contract call
  • Emits ContributionRouted event: sender, campaign, dest_amount, source_amount, fee_amount
  • 4 unit tests: happy path split, slippage rejection, zero fee, zero dest_amount — all passing

backend/src/services/sorobanService.js

  • Add routeContribution() — encodes args as ScVals and calls invokeContract

backend/src/services/stellarService.js

  • prepareSignedContributionPathPayment() checks ROUTER_CONTRACT_ID:
    • Set → routes through the Soroban contract (trustless, on-chain slippage + atomic fee split)
    • Unset → falls back to existing classic path payment (backward compatible)
  • Existing contribution UI works unchanged

backend/.env.example

  • Add ROUTER_CONTRACT_ID, XLM_SAC_ADDRESS, USDC_SAC_ADDRESS

…Savitura#60)

- contracts/soroban/contracts/router/src/lib.rs: RouterContract
  - route_contribution() validates send_max <= dest_amount*(1+slippage_bps/10000)
  - atomically splits dest_amount: (1-fee_bps/10000) to campaign, fee_bps/10000 to platform
  - emits ContributionRouted event (sender, campaign, dest_amount, source_amount, fee_amount)
  - 4 unit tests: happy path, slippage rejection, zero fee, zero dest_amount
- sorobanService.js: add routeContribution() wrapper
- stellarService.js: prepareSignedContributionPathPayment() routes through contract
  when ROUTER_CONTRACT_ID is set; falls back to classic path payment otherwise
- backend/.env.example: add ROUTER_CONTRACT_ID, XLM_SAC_ADDRESS, USDC_SAC_ADDRESS
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 29, 2026

@cybermax4200 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

…licate txHash declaration in contributions.js
…stination_key, and valid password in test fixtures
@cybermax4200
Copy link
Copy Markdown
Contributor Author

image

please merge, the CI has passed successfully

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.

Soroban: On-chain contribution router with slippage enforcement

1 participant