Skip to content

feat(sponsors): add pool stats, deposit/withdraw XDR methods and unit tests#48

Merged
EmeditWeb merged 2 commits into
StepFi-app:mainfrom
Iwayemi-Kehinde:main
Jun 18, 2026
Merged

feat(sponsors): add pool stats, deposit/withdraw XDR methods and unit tests#48
EmeditWeb merged 2 commits into
StepFi-app:mainfrom
Iwayemi-Kehinde:main

Conversation

@Iwayemi-Kehinde

@Iwayemi-Kehinde Iwayemi-Kehinde commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Add getPool(), buildDepositXdr(), and buildWithdrawXdr() to SponsorsService

Closes #8

Overview

Replaces the existing deposit() placeholder with real contract client delegation and adds full pool aggregation and XDR builder methods with test coverage.


Changes

src/modules/sponsors/sponsors.service.ts

  • Inject LiquidityPoolContractClient into the constructor
  • Add MIN_WITHDRAWAL_SHARES = 1 constant
  • getPool() — aggregates totalDeposited and totalShares from the liquidity pool contract, queries active loans from Supabase, and computes:
    • utilizationBps = Math.round((totalLoaned / totalDeposited) * 10_000)
    • apyBps = Math.round(weightedAvgInterestRate * 0.85 * 100)
  • buildDepositXdr(wallet, amount) — validates amount > 0, converts to stroops, delegates to liquidityClient.buildDepositTx(), returns the unsigned XDR
  • buildWithdrawXdr(wallet, shares) — validates shares >= MIN_WITHDRAWAL_SHARES, converts to stroops, delegates to liquidityClient.buildWithdrawTx(), returns the unsigned XDR

src/modules/sponsors/sponsors.module.ts

  • Import StellarModule so LiquidityPoolContractClient is injectable

test/unit/modules/sponsors/sponsors.service.spec.ts (new)

  • getPool — verifies aggregation, utilization math, APY math, empty loan edge case, zero-pool fallback, and contract error propagation
  • buildDepositXdr — verifies valid XDR, correct stroops conversion, rejection of amount ≤ 0, and contract error surfacing
  • buildWithdrawXdr — verifies valid XDR, correct stroops conversion, rejection below MIN_WITHDRAWAL_SHARES, and contract error surfacing
  • register / getMyPool / getStats — coverage for existing methods to reach ≥ 85%
  • Zero any types used throughout

Testing

npm test -- sponsors.service    # passes
npm run test:cov                # coverage ≥ 85%
npm run build                   # zero TypeScript errors

cto-new Bot added 2 commits June 18, 2026 01:50
…deposit-withdraw-xdr-tests

feat: add getPool(), buildDepositXdr(), buildWithdrawXdr() to SponsorsService with comprehensive unit tests
@EmeditWeb EmeditWeb merged commit 1793032 into StepFi-app:main Jun 18, 2026
1 check passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Jun 18, 2026
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[16] Add unit tests for SponsorsService

2 participants