Skip to content

refactor(adapter-stellar): extract shared Soroban RPC server factory #339

@pasevin

Description

@pasevin

Summary

The Stellar adapter (packages/adapter-stellar/) has 7 independent RPC/network client creation sites, with 5 near-identical getSorobanRpcServer implementations copy-pasted across files. This is a DRY violation that also causes inconsistent behavior — some call sites skip userRpcConfigService and allowHttp, meaning they won't respect user RPC overrides or work on localhost.

Duplication Map

# File Uses userRpcConfigService? allowHttp?
1 transaction/sender.ts Yes Yes
2 transaction/eoa.ts Yes Yes
3 transaction/relayer.ts No Yes
4 query/handler.ts Yes Yes
5 contract/type.ts Yes Yes
6 access-control/onchain-reader.ts No No
7 contract/loader.ts No (different client type) N/A

Sites 1, 2, 4, 5 are virtually identical. Site 3 (relayer) and site 6 (access-control) skip userRpcConfigService, which means user RPC overrides are silently ignored. Site 6 also skips allowHttp, breaking localhost development.

Proposed Solution

  1. Create a shared createSorobanRpcServer(networkConfig) utility (e.g. in configuration/rpc.ts or a new utils/soroban-client.ts) that:

    • Resolves RPC URL via userRpcConfigService with fallback to networkConfig.sorobanRpcUrl
    • Applies allowHttp for localhost URLs
    • Returns StellarRpc.Server
  2. Replace all 6 Server creation sites with the shared utility

  3. Align relayer.ts and access-control/onchain-reader.ts to use userRpcConfigService (bug fix)

Context

This was identified while doing the same refactor on the EVM adapter (createEvmPublicClient utility in utils/public-client.ts on branch 011-evm-access-control). The EVM side is already consolidated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions