Skip to content

feat: Implement Soroban lending adapter concrete implementation #53

@YaronZaki

Description

@YaronZaki

Problem Statement

quantara/soroban/adapters/LendingAdapter.py defines a comprehensive abstract interface with 8 methods for lending protocol integration, but zero concrete implementations exist. The factory's _adapters dict is empty. The entire lending/borrowing flow is stubbed.

Evidence

# quantara/soroban/adapters/LendingAdapter.py
class LendingAdapterFactory:
    _adapters: Dict[str, type] = {}  # EMPTY — no implementations
    @classmethod
    def create(cls, name: str, **kwargs) -> LendingAdapter:
        if name not in cls._adapters:
            raise ValueError(f"Unknown lending adapter: {name}.")  # Always raises!

The abstract interface defines: get_reserve_data, get_user_position, deposit, withdraw, borrow, repay, enable_collateral, disable_collateral, get_all_reserves — all unimplemented.

Impact

High — core feature gap. Users cannot: view lending APY rates, deposit collateral, borrow against collateral, repay loans, or view lending positions. The entire "borrow" side of the leverage protocol is missing.

Proposed Solution

Implement a concrete LendingAdapter for a Stellar-native lending protocol (e.g., Blend). Implement all 8 abstract methods with Soroban RPC calls. Register with LendingAdapterFactory for dynamic instantiation.

Technical Requirements

  • Must implement ALL 8 abstract methods from LendingAdapter ABC
  • Must handle Stellar token decimals (7 decimal places)
  • Must use async HTTP via aiohttp (consistent with StellarClient in blockchain_call.py)
  • Must register with LendingAdapterFactory._adapters

Acceptance Criteria

  • Concrete LendingAdapter implementation exists for a Stellar lending protocol
  • All 8 abstract methods implemented with working Stellar network calls
  • Adapter registered with factory and instantiable via LendingAdapterFactory.create("protocol_name")
  • Integration tests verify deposit, borrow, repay, withdraw, position queries on Stellar testnet
  • Error handling follows existing patterns (specific exceptions, proper logging)
  • Documentation added for which protocol was integrated and configuration needed

Implementation Notes

Coordinate with team on which Stellar lending protocol to integrate (Blend, Aqua, or custom Soroban contract). Follow async patterns in StellarClient (quantara/web_app/contract_tools/blockchain_call.py). Methods will need to construct and submit Soroban contract invocations.

File Map

  • quantara/soroban/adapters/LendingAdapter.py — register concrete implementation in factory
  • quantara/soroban/adapters/blend_adapter.pyNew: concrete Blend adapter (or similar)
  • quantara/soroban/adapters/__init__.py — export new adapter
  • quantara/web_app/contract_tools/ — wire adapter into contract tools layer

Dependencies

  • Related: REPO-014 (AMM adapter needed for liquidation swaps)
  • Related: REPO-039 (USDC issuer must be configured)

Testing Strategy

  • Unit: Test each method with mocked Soroban RPC responses
  • Integration: Test against Stellar testnet: deposit XLM, borrow USDC, verify position, repay, withdraw
  • Manual: End-to-end flow through frontend: connect wallet → deposit → borrow → monitor → repay → withdraw

Security Considerations

Financial protocol — incorrect implementation could lead to fund loss. Test edge cases: insufficient collateral, liquidation scenarios, max borrow amounts, rounding errors. Use Decimal for all arithmetic. Validate all inputs before blockchain submission.

Definition of Done

  • Code implemented and peer-reviewed by at least 2 reviewers
  • Tests written and passing (unit + integration on testnet)
  • Documentation updated
  • No new linting errors
  • Security considerations addressed
  • PR linked and merged

Labels: feature, high-impact
Priority: High
Difficulty: Expert
Estimated Effort: 2w

Metadata

Metadata

Assignees

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