feat(sponsors): add pool stats, deposit/withdraw XDR methods and unit tests#48
Merged
Conversation
…sService with comprehensive unit tests
…deposit-withdraw-xdr-tests feat: add getPool(), buildDepositXdr(), buildWithdrawXdr() to SponsorsService with comprehensive unit tests
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
getPool(),buildDepositXdr(), andbuildWithdrawXdr()to SponsorsServiceCloses #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.tsLiquidityPoolContractClientinto the constructorMIN_WITHDRAWAL_SHARES = 1constantgetPool()— aggregatestotalDepositedandtotalSharesfrom 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)— validatesamount > 0, converts to stroops, delegates toliquidityClient.buildDepositTx(), returns the unsigned XDRbuildWithdrawXdr(wallet, shares)— validatesshares >= MIN_WITHDRAWAL_SHARES, converts to stroops, delegates toliquidityClient.buildWithdrawTx(), returns the unsigned XDRsrc/modules/sponsors/sponsors.module.tsStellarModulesoLiquidityPoolContractClientis injectabletest/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 propagationbuildDepositXdr— verifies valid XDR, correct stroops conversion, rejection ofamount ≤ 0, and contract error surfacingbuildWithdrawXdr— verifies valid XDR, correct stroops conversion, rejection belowMIN_WITHDRAWAL_SHARES, and contract error surfacingregister/getMyPool/getStats— coverage for existing methods to reach ≥ 85%anytypes used throughoutTesting