Context:
StellarSwipe uses Soroban smart contracts for automated trade execution with risk gates. The backend needs to interact with deployed contracts.
Problem:
Create a service that connects to Soroban RPC, invokes contract methods, and handles transaction submission.
What Done Looks Like:
- Soroban client service
- Contract method invocation helpers
- Transaction simulation before submission
- Error handling for contract failures
- Network fee estimation
Folder Structure:
src/
├── soroban/
│ ├── soroban.service.ts
│ ├── soroban.module.ts
│ ├── contracts/
│ │ ├── trade-executor.contract.ts
│ │ └── stake-manager.contract.ts
│ ├── dto/
│ │ └── invoke-contract.dto.ts
│ └── interfaces/
│ └── contract-result.interface.ts
Implementation Guidelines:
- Use
@stellar/stellar-sdk SorobanRpc namespace
- Configure RPC URL from environment
- Implement contract invocation wrapper
- Simulate transactions before submission
- Parse contract events from results
- Handle network congestion (Protocol 23 parallel execution)
Key Methods:
invokeContract(contractId, method, params)
simulateTransaction(tx)
getContractEvents(txHash)
estimateFees(operation)
Edge Cases:
- Contract execution failure
- Insufficient balance for fees
- Network timeout
- Invalid contract parameters
Validation:
- Successfully invoke test contract
- Simulation detects errors
- Events parsed correctly
- Fee estimation accurate
Context:
StellarSwipe uses Soroban smart contracts for automated trade execution with risk gates. The backend needs to interact with deployed contracts.
Problem:
Create a service that connects to Soroban RPC, invokes contract methods, and handles transaction submission.
What Done Looks Like:
Folder Structure:
Implementation Guidelines:
@stellar/stellar-sdkSorobanRpc namespaceKey Methods:
invokeContract(contractId, method, params)simulateTransaction(tx)getContractEvents(txHash)estimateFees(operation)Edge Cases:
Validation: