refactor(soroban): separate concerns into clean contract-execution su…#403
Merged
Solomonsolomonsolomon merged 1 commit intoJun 1, 2026
Conversation
…bsystem - errors.ts: typed SorobanError hierarchy with machine-readable codes - sdkAdapter.ts: single point of stellar-sdk access with version-detection - simulator.ts: pure simulation layer (build tx → RPC → raw result) - decoder.ts: isolated XDR/ScVal → native JS decoding - signingPrep.ts: auth detection, transaction assembly, and signing - invoker.ts: orchestrates simulate → assert → decode pipeline - sorobanService.ts: thin facade preserving backward-compatible API - index.ts: unified public API export for the subsystem
|
@GreatShinro 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor(soroban): separate concerns into clean contract-execution subsystem
Summary
sorobanService.tswas a single 366-line file that mixed SDK version detection, transaction building, simulation, auth checking, XDR decoding, and error handling in one place. It also contained a partially-written class body embedded inside a function, dead code paths, and unreachable statements.This PR replaces it with a layered subsystem where each concern lives in its own module with a single responsibility.
What changed
New files
src/services/soroban/errors.tsSorobanErrorbase + 8 subclasses, each with a machine-readableSorobanErrorCodediscriminantsrc/services/soroban/sdkAdapter.ts@stellar/stellar-sdkaccess; version-detection forSorobanRpc.Servervs legacySoroban.Server;nativeToScVal/scValToNativewrappers; network constantssrc/services/soroban/simulator.tssimulateTransaction, returns raw result + resource estimates + auth entries. No decoding, no signingsrc/services/soroban/decoder.tsdecodeReturnValueanddecodeScValhandle both current and legacy SDKretvalshapessrc/services/soroban/signingPrep.tsrequiresSigning), transaction assembly viaSorobanRpc.assembleTransactionwith a manual fallback, and keypair signingsrc/services/soroban/invoker.tsinvokeContractandestimateContractModified files
src/services/sorobanService.tsSorobanServiceclass for backward compatibilitysrc/services/soroban/index.tsttlManager,swapLock,reentrancyGuard, andxdrScopingmodulesArchitecture
Each layer imports only from layers below it. No circular dependencies.
Backward compatibility
invokeContract(params)— same signature, same return shapeSorobanServiceclass withinvokeContractandsimulateContractCallmethods — preservedsorobanServicesingleton — preservedsrc/services/soroban/index.ts(ttlManager,swapLock,reentrancyGuard,xdrScoping) — unchangedWhat was removed
SorobanServiceclass body embedded insideinvokeContractLivefunction (unreachable code)export const sorobanServiceinside a function body (syntax error)tryblock after areturnstatement innormalizeArgsTesting
npx tsc --noEmitpasses with zero new errors (one pre-existing error inpackages/sdk/src/trustline.tsis unrelated)SorobanTool,SorobanContractStateTool) import fromsorobanServiceunchanged and continue to workcloses #332