Repository navigation
fix(backend): correct stroop units in loan request, score breakdown, dispute and deposit paths - #2208
Merged
K1NGD4VID merged 1 commit intoOct 28, 2026
Conversation
Malware detection scan flagged this pull requestThe scan found 1 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.
This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional. |
…paths Requesting a loan compared a human-readable token amount against a pool balance in stroops, the score breakdown dropped every computed statistic for users without a scores row, contesting a default wrote an invalid event outside a transaction, and deposit slippage bounds skipped the 10^7 scaling. Compare in stroops, aggregate the score CTE, write the dispute and its event atomically with the NOT NULL columns filled, and scale minSharesOut through the money policy with schema coverage. Closes LabsCrypt#2019 Closes LabsCrypt#2020 Closes LabsCrypt#2021 Closes LabsCrypt#2022 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
alagbesadat208-prog
force-pushed
the
fix/backend-2019-2022
branch
from
October 28, 2026 14:09
a8f621b to
64e7c88
Compare
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.
Summary
Four backend fixes, one per issue. All changes are covered by tests.
#2019 —
requestLoancompared tokens against stroopsreq.body.amountis in human-readable token units, whilesorobanService.getPoolBalance()returns raw stroops (10^7 per token). The pre-flight check compared the two numbers directly, so it was off by 10^7.toStroops(amount.toString())against the balance in stroops.money/decimal.ts, trailing settlement zeros trimmed).#2021 —
getScoreBreakdownreturned an empty breakdown for users without ascoresrowcurrent_score_ctehad no aggregate, so it produced 0 rows for users with loan activity incontract_eventsbut noscoresrow. TheCROSS JOINs then discarded every computedloan_stats/timing_statsvalue.COALESCE(MAX(current_score), 500)so the CTE always yields exactly one row.updateScorealready invalidatesscore:breakdown:${userId}— confirmed, no change needed.#2020 —
contestDefaultwrote an invalid event outside a transactionloan_disputesinsert and thecontract_eventsmarker in onewithTransaction, so a failed event insert no longer leaves an orphaned dispute row.contract_events:event_id(randomUUID()),ledger: 0,tx_hash: dispute:<disputeId>,contract_idfromLOAN_MANAGER_CONTRACT_ID(fallbackoffchain_dispute), matching the admin dispute endpoints.#2022 —
buildDepositTxleftminSharesOutunscaled and the schema dropped itminSharesOutwithtoStroops(minSharesOut.toString())before encoding it asi128, so the slippage bound is no longer 10^7 times too small (and fractional values no longer throwRangeError).minSharesOut: z.number().nonnegative().optional()tobuildPoolTransactionSchema.Tests
sorobanService.stroops.test.ts: assertsminSharesOut(integer and fractional) is scaled to stroops.loanEndpoints.test.ts: pool-liquidity pre-flight accepts/rejects in token units and formats the shortfall in tokens.scoreBreakdown.test.ts: asserts the score CTE is aggregated so event stats survive.loanDispute.test.ts/integration/loanDisputeFlow.test.ts: run throughwithTransactionand assert the dispute event suppliesevent_id,ledger,tx_hashandcontract_id.validation.test.ts:minSharesOutis accepted, optional, and rejects negatives.npm run typecheckpasses,eslintreports no errors on the touched files, and the full backend suite passes (124 suites, 1066 tests; 4 suites skipped).Closes #2019
Closes #2020
Closes #2021
Closes #2022