Skip to content

Wire StellarService contract methods into the account creation and sweep flows #99

@phertyameen

Description

@phertyameen

Summary

StellarService has contract interaction methods implemented (Issues #74#80), but none of them are actually called from the modules that need them. AccountsService calls stellarService.createEphemeralAccount() but that method does not yet invoke EphemeralAccount.initialize() on the contract. SweepsService uses ContractProvider which simulates but never submits the contract call. This issue connects the implemented contract methods to the flows that need them, making the SDK actually enforce on-chain restrictions during account creation and sweep execution.

Background

The two disconnected layers
The SDK currently has two parallel but unconnected paths for interacting with the Stellar network:
The StellarService layer (added in Issues #74#80) is built specifically for Soroban contract interactions. It has initializeContract(), executeSweep() (the contract version), and recordPayment() all implemented and awaiting use.
The ContractProvider layer (existing code in the sweeps module) also attempts to call the contract's sweep() function, but only simulates the transaction, it never submits it. It was built as a placeholder and its authorizeSweep() method returns an auth hash without any confirmed on-chain state change.

Right now, account creation creates a Stellar account on Horizon but never calls EphemeralAccount.initialize(). Sweep execution calls ContractProvider.authorizeSweep() which simulates but does not submit, then calls TransactionProvider to move funds via a classic Horizon payment. The contract is never actually invoked in either flow.

What needs to change in account creation

AccountsService.create() calls stellarService.createEphemeralAccount(). That method needs to be updated (per Issue #76's implementation) to call EphemeralAccount.initialize() immediately after the Horizon CreateAccount operation. The expiry_ledger, creator, and recovery_address values needed by initialize() are all available from the CreateAccountDto and the funding keypair. The contract ID should come from environment config.

What needs to change in the sweep flow

SweepsService currently calls contractProvider.authorizeSweep() which simulates the contract call. This should be replaced with stellarService.executeSweep() which actually submits the SweepController.execute_sweep() transaction. Once the contract call is confirmed, TransactionProvider.executeSweepTransaction() should still be called for the classic Horizon payment, the contract enforces authorization, the Horizon payment moves the funds. Both are needed.

ContractProvider is not deleted by this issue. It may still be useful for the simulation step (checking before submitting), but its authorizeSweep() should no longer be the authoritative contract interaction for the sweep flow.

Dependency between the two changes

Account creation must initialize the contract first. Without initialize() being called, the contract has no state, and any subsequent executeSweep() call will return Error::NotInitialized. Get account creation wired up and tested on testnet before changing the sweep flow.

Environment configuration needed

Two contract addresses need to be in environment config and .env.example:

STELLAR_EPHEMERAL_CONTRACT_ID: the deployed EphemeralAccount contract address
STELLAR_SWEEP_CONTROLLER_CONTRACT_ID: the deployed SweepController contract address

These require a deployed contract on Stellar testnet. See the bridgelet-core README for deployment instructions if the contracts are not yet deployed.or ask directly as a comment under this issue if assigned.

Where to look

  • src/modules/stellar/stellar.service.ts: createEphemeralAccount(), executeSweep(), initializeContract()
  • src/modules/accounts/accounts.service.ts: the create() method
  • src/modules/sweeps/sweeps.service.ts: the executeSweep() method
  • src/modules/sweeps/providers/contract.provider.ts: the current simulation-only approach being replaced
  • bridgelet-core README: deployment instructions for testnet

Metadata

Metadata

Assignees

No one assigned

    Labels

    criticalVery important for the project to function.enhancementNew feature or requestnestjsBackend frameworksorobansmart contract language

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions