Skip to content

Contract adapter returns hardcoded execution mode #237

Description

@usmanimamu17-create

Labels / Complexity: enhancement, contracts · Medium — 4 pts

Problem

The SLAContractAdapter.get_runtime_metadata() method in app/services/contracts/sla_adapter.py returns settings.CONTRACT_EXECUTION_MODE which is read from the environment variable. However, the actual execution path in calculate_sla() always calls the local SLACalculator.calculate(), ignoring the execution mode. The adapter claims to support both "local" and "soroban" modes, but there is no integration with the actual Soroban contract.

Root cause

# app/services/contracts/sla_adapter.py:23-28
@staticmethod
def get_runtime_metadata() -> dict[str, str]:
    return {
        "contract_address": settings.SLA_CONTRACT_ADDRESS,
        "network": settings.STELLAR_NETWORK,
        "execution_mode": settings.CONTRACT_EXECUTION_MODE,  # <-- Read but not used
    }

Why this is architecturally hard

  1. The Soroban contract uses different data types (Symbol, Address, u32) than the local Python calculator; the translation layer (translate_contract_result) exists but is not wired to a real Soroban client.
  2. The backend would need to manage a Soroban RPC connection and handle transaction submission, signing, and confirmation.
  3. The contract's calculate_sla function requires an outage_id: Symbol and severity: Symbol, which must be validated and converted from Python strings.

Proposed design

  • Add a SorobanClient class in app/services/contracts/soroban_client.py that wraps the Stellar SDK
  • In SLAContractAdapter.calculate_sla(), check settings.CONTRACT_EXECUTION_MODE and dispatch to either local calculator or Soroban client
  • The Soroban client handles transaction building, signing with the pool wallet key, and waiting for confirmation

Downstream impact

Requires coordination with apexchainx-contracts for the contract ABI and entry points. The contract must be deployed and the address configured in SLA_CONTRACT_ADDRESS.

Acceptance criteria

  • Setting CONTRACT_EXECUTION_MODE=soroban routes SLA calculations to the Soroban contract
  • The adapter correctly translates between Python types and Soroban Symbol/u32 types
  • A test with a mock Soroban client verifies the routing logic

Out of scope

Deploying the contract; assume a deployed contract address is configured.

Getting started

Files in scope:

  • app/services/contracts/sla_adapter.py
  • app/services/contracts/soroban_client.py (new file)
  • app/core/config.py

Build/test commands:

pytest tests/test_contract_parity.py

Good first files to read: app/services/contracts/sla_adapter.py, app/services/contracts/translation.py, docs/STELLAR_INTEGRATION.md.

Metadata

Metadata

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third Campaignarea/smart-contractSoroban/Stellar contract adapter, parity tests, on-chain invariantsenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions