Skip to content

feat: Integrate Stellar Asset Interface (SAI) Wrapper#186

Open
emmanuelist wants to merge 1 commit intoStellarDevHub:mainfrom
emmanuelist:feat/sai-wrapper
Open

feat: Integrate Stellar Asset Interface (SAI) Wrapper#186
emmanuelist wants to merge 1 commit intoStellarDevHub:mainfrom
emmanuelist:feat/sai-wrapper

Conversation

@emmanuelist
Copy link
Copy Markdown
Contributor

Summary

Implements the Stellar Asset Interface (SAI) Wrapper contract to allow the lab to accept XLM/USDC payments for premium certificates via the Soroban token interface.

Closes #131

Changes

New: contracts/src/sai_wrapper.rs

A standalone Soroban contract that wraps native Stellar Asset Contracts (SAC) to provide a payment gateway for premium certificates:

  • init(admin, treasury, asset_contract, cert_price) — One-time setup with admin, treasury, initial accepted asset, and price
  • payment_gateway(payer, asset_contract) — Core payment function that:
    1. Requires payer authorization
    2. Validates the asset is in the accepted registry
    3. Pre-flight checks payer balance (fails fast before transfer)
    4. Transfers cert_price tokens from payer → treasury via SAC token::Client
    5. Verifies transfer completion (treasury balance increased by exact amount)
    6. Records payment status and emits tracking event
  • has_paid(payer) — Query whether a payer has completed payment
  • get_balance(asset, account) — Wrapped balance lookup via SAC
  • Multi-asset supportadd_accepted_asset / remove_accepted_asset for admin-managed asset registry (XLM + USDC + any SAC)
  • set_cert_price(admin, asset, price) — Admin-only price updates per asset
  • get_total_collected(asset) — Total payments collected per asset

Bug fixes (pre-existing)

  • token.rs: Fixed unclosed delimiter in burn() — duplicate authorization check left the if block unclosed
  • token.rs: Fixed double require_auth in update_uri()only_owner() already calls require_auth, second call triggered Auth::ExistingValue error
  • tests.rs: Fixed unclosed delimiter in batch_issue_gas_efficiency() — duplicate for loop left a dangling open brace
  • lib.rs: Fixed events().publish() call in batch_issue() — was passing 3 arguments instead of 2

Tests

14 new tests covering all SAI wrapper requirements:

Test Scenario
payment_transfers_tokens_and_records_paid Full payment flow: transfer + balance verification + has_paid
total_collected_tracks_payments Cumulative payment tracking
has_paid_returns_false_for_unknown_address Default state check
payment_rejects_insufficient_balance Payer with 0 tokens rejected
payment_rejects_unaccepted_asset Unregistered SAC rejected
multi_asset_payments XLM + USDC (second SAC) both accepted
admin_can_update_cert_price Price update flow
non_admin_cannot_update_price Unauthorized price change rejected
admin_can_remove_asset Asset deregistration
double_init_panics Double initialization prevented
get_balance_returns_correct_amount Wrapped balance query
get_treasury_returns_configured_address Treasury query
init_rejects_zero_price Zero price validation
set_cert_price_rejects_negative Negative price validation

Full suite: 102 tests pass, 0 failures.

)

- Add sai_wrapper.rs: Soroban contract wrapping native Stellar Assets
  (XLM, USDC) via SAC token interface for premium certificate payments
- Implement payment_gateway function with transfer verification
- Support multi-asset acceptance with admin-managed asset registry
- Pre-flight balance checks prevent failed transfers
- Treasury balance verification confirms transfer completion
- 14 comprehensive tests: payment flow, insufficient balance,
  unaccepted asset, multi-asset, admin controls, edge cases
- Fix pre-existing syntax errors in token.rs and tests.rs
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

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

@emmanuelist
Copy link
Copy Markdown
Contributor Author

Note on CI failures: The 4 failing checks (Backend CI, Frontend CI, Backend Lint, Frontend Lint) are pre-existing upstream issues unrelated to this PR.

@emmanuelist
Copy link
Copy Markdown
Contributor Author

@ayomideadeniran , kindly merge this PR. Thanks

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.

[Integrate] Stellar Asset Interface (SAI) Wrapper

1 participant