Skip to content

Feat: integrate backend with Soroban contract#45

Open
ebubechi-ihediwa wants to merge 2 commits intoTevaLabs:mainfrom
ebubechi-ihediwa:feat/integrate-soroban-contract-hybrid-modes
Open

Feat: integrate backend with Soroban contract#45
ebubechi-ihediwa wants to merge 2 commits intoTevaLabs:mainfrom
ebubechi-ihediwa:feat/integrate-soroban-contract-hybrid-modes

Conversation

@ebubechi-ihediwa
Copy link
Contributor

Wire backend prediction logic to Soroban smart contract for hybrid on-chain/off-chain architecture.

Core Integration:

  • Implement Predict (place_bet) and Resolve (resolve_round) contract calls via soroban.service.ts
  • Add createRound() for on-chain round creation with price/duration validation
  • Mode-aware interaction: UP_DOWN fully integrated, LEGENDS returns 501 Not Implemented
  • Centralize all blockchain operations with structured error handling and retry logic

Error Handling & Resilience:

  • Structured error classification (TRANSIENT, VALIDATION, INSUFFICIENT_FUNDS, CONTRACT_ERROR, TIMEOUT, UNKNOWN)
  • Automatic retry with exponential backoff for network failures (3 retries, 30s timeout)
  • Database rollback on blockchain failure during critical operations
  • Graceful degradation: user payouts complete even if blockchain unavailable
  • Clear error surfacing with proper HTTP status codes (400, 503, 504)

Testing:

  • E2E test suite (18 tests) validates complete round lifecycle
  • Mock blockchain client enables testing without deployed contract
  • Tests cover: round creation, predictions, resolution, errors, authorization
  • Database-only mode for CI/CD environments

Configuration:

  • SOROBAN_CONTRACT_ID, SOROBAN_NETWORK, SOROBAN_RPC_URL
  • SOROBAN_ADMIN_SECRET (round operations), SOROBAN_ORACLE_SECRET (price resolution)
  • Service gracefully degrades when Soroban not configured

Files Modified:

  • src/services/soroban.service.ts (blockchain integration layer)
  • src/services/round.service.ts (integrated round creation)
  • src/services/prediction.service.ts (integrated bet placement)
  • src/services/resolution.service.ts (integrated resolution)
  • src/routes/rounds.routes.ts, predictions.routes.ts (error handling)
  • src/tests/soroban-integration.e2e.test.ts (test suite)
  • src/tests/setup.ts (test utilities)
  • src/types/xelma-bindings.d.ts (type declarations)
  • src/middleware/auth.middleware.ts (fixed duplicates)

Closes #24

Wire backend prediction logic to Soroban smart contract for hybrid on-chain/off-chain architecture.

- Implement Predict and Resolve contract calls via soroban.service.ts
- Add mode-aware interaction (UP_DOWN on-chain, LEGENDS returns 501)
- Centralize blockchain operations with retry logic and error classification
- Handle failures gracefully with database rollback and transient error retry
- Add E2E test suite validating complete prediction flow
- Support database-only mode when blockchain not configured

Closes TevaLabs#24
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 Backend with Soroban Contract (Hybrid Modes)

1 participant