Skip to content

Closes #1125 Implemented Soroban Transaction Service - #146

Open
p3ris0n wants to merge 25 commits into
Web3Novalabs:mainfrom
p3ris0n:feat/rpc-transact=service
Open

Closes #1125 Implemented Soroban Transaction Service#146
p3ris0n wants to merge 25 commits into
Web3Novalabs:mainfrom
p3ris0n:feat/rpc-transact=service

Conversation

@p3ris0n

@p3ris0n p3ris0n commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Description

This PR implements the backend proxy and transaction assembly service for the AutoShare Soroban contract (Closes #125).

Because the backend server never holds a user's secret key, it cannot directly sign Soroban smart contract invocations. Instead, we've implemented a robust "prepare-sign-submit" lifecycle where the backend acts as an RPC gateway: it simulates the transaction, calculates fees, assembles the XDR, and relies on the frontend client for wallet signatures before safely submitting the transaction back to the network.

Key Features & Changes

  • Environment & Configuration:
    • Added strict environment validation for SOROBAN_RPC_URL, SOROBAN_NETWORK_PASSPHRASE, and AUTOSHARE_CONTRACT_ID. The backend will fail-fast at boot if these are missing.
  • Soroban Service (services/soroban.ts):
    • Integrated @stellar/stellar-sdk v16 rpc.Server.
    • Added prepareTransaction to simulate smart contract calls, calculate resource footprints, and build an assembled Transaction with an automatic 1.2x resource fee multiplier.
    • Added submitTransaction which safely submits the signed XDR to the network and implements robust exponential backoff polling (getTransaction) to verify execution.
    • Implemented SorobanSimulationError which intercepts raw VM errors and elegantly maps Soroban Error Codes (1-20) back into our human-readable AutoShareError variants (e.g., GroupAlreadyExists, InsufficientBalance).
  • REST Endpoints (routes/contract.ts):
    • POST /api/contract/groups/:id/distribute/prepare: Secured endpoint that ensures only the Group Creator can initialize a distribution. Returns the unsigned XDR.
    • POST /api/contract/tx/submit: Endpoint to accept the wallet-signed XDR payload and pipe it through the Soroban Service. Returns standardized 400 errors for malformed XDR or simulated VM errors, and 503 for retriable timeouts.
  • Data Serialization (utils/scval.ts):
    • Implemented safe type parsers to cross the JS-to-WASM boundary, safely decoding xdr.ScVal types for Address, u32, i128 (as strings to prevent precision loss), and mapping our custom AutoShareDetails and GroupMember structs.
  • Testing:
    • Added robust Node test runner suites for scval.test.ts, soroban.test.ts (mocked RPC transport), and contract.test.ts (Supertest API integration).
  • Housekeeping:
    • Fixed multiple Rust clippy lints and redundant cfg(test) declarations in the contract/ workspace that were blocking pre-push hooks.

Verification

  • All backend unit and integration tests passing (pnpm --filter backend test)
  • Pre-push hooks green (cargo fmt, cargo clippy, eslint, tsc)
  • Smart contract simulations accurately map rust-level enum variants to REST error codes.
  • Submission handles txBadSeq without hanging.

Next Steps

Following this merge, the frontend interface can be updated to consume /prepare, sign the XDR payload with Freighter, and push to /submit.

@Yunusabdul38

Copy link
Copy Markdown
Contributor

@p3ris0n kindly resolve ci

@Yunusabdul38

Copy link
Copy Markdown
Contributor

@p3ris0n, kindly resolve the failed CI check

@martinvibes

Copy link
Copy Markdown

@p3ris0n Nice job but pls fix conflicts and make sure ci is passing

@martinvibes martinvibes left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@p3ris0n pls remove the test_snapshots/test folder

@martinvibes

Copy link
Copy Markdown

remove pnpm-lock.yaml file too

p3ris0n and others added 16 commits August 25, 2026 18:00
… feat/rpc-transact=service

# Conflicts:
#	contract/src/base/errors.rs
#	contract/src/base/events.rs
#	contract/src/lib.rs
#	contract/src/test_schedule.rs
#	contract/test_snapshots/test/test_distribute_requires_auth.1.json
Co-authored-by: Cursor <cursoragent@cursor.com>
pnpm 8 ignored lockfileVersion 9.0 and failed frozen-lockfile installs.

Co-authored-by: Cursor <cursoragent@cursor.com>
CI no longer depends on lockfileVersion matching the runner pnpm.

Co-authored-by: Cursor <cursoragent@cursor.com>
… feat/rpc-transact=service

# Conflicts:
#	backend/.env.example
#	backend/src/services/contractReader.ts
Degrade indexer health when the cursor query fails, use in-memory groups in test, and align OpenAPI/auth/schema tests with node:test, SEP-10, and Zod.

Co-authored-by: Cursor <cursoragent@cursor.com>
@noble/ed25519 used by Keypair.random() requires crypto.getRandomValues, which is not global on Node 18.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

feat(backend): Soroban RPC transaction service — build, simulate, assemble, submit, poll, plus a full ScVal codec

3 participants