fix: align repay function name between XDR builder and transaction checker#90
fix: align repay function name between XDR builder and transaction checker#90khaylebfortune wants to merge 3 commits into
Conversation
…ecker The deployed creditline contract function is 'repay_installment' but the transaction status checker was looking for 'repay_loan'. This mismatch meant successful on-chain repayments never triggered the follow-up loan balance deduction — loans appeared unpaid indefinitely. Changes: - transaction-status-checker.service.ts: check for 'repay_installment' - creditline.client.ts: fix error log to match actual function name - loans.controller.ts, loan-payment-response.dto.ts: update Swagger docs - Add alignment test to prevent future drift Closes StepFi-app#62
EmeditWeb
left a comment
There was a problem hiding this comment.
Review verdict: ✅ APPROVE with minor corrections
Good catch and a real fix. The status-checker matched functionName === 'repay_loan' while the XDR builder emits repay_installment, so the checker never recognized any repayment — all repayment follow-up/status tracking was silently broken. Realigning to repay_installment is correct, and the checker's nativeArgs[1]=loanId, nativeArgs[2]=amount parsing matches what the builder actually emits (contract.call('repay_installment', userArg, loanIdArg, amountArg), 3 args). Doc strings + Swagger updated consistently; no any added.
Minor corrections:
- The new test reads the two source files as text and regex-matches function names. That's brittle — a formatting change breaks it. Prefer asserting on the actual built XDR / decoded operation args.
buildRepayLoanTxis now a misnomer (it buildsrepay_installment). Consider renaming for clarity.
repay_installment with 3 args (borrower, loanId, amount), but the creditline contract source defines repay_installment(borrower, loan_id, installment_index, amount) — 4 args. If the deployed contract matches the repo, every repayment transaction the API builds would fail on-chain (arg-count/type mismatch). Please verify the API's builder against the deployed contract signature and open a follow-up if they disagree — this is a money-path blocker independent of this PR.
…tle test to assert on decoded XDR
|
@EmeditWeb thanks for the review. I've addressed both issues. |
There was a problem hiding this comment.
Re-audit for merge: ⚠️ Request changes — I WILL NOT merge yet (money-critical arg mismatch) @khaylebfortune
The rename repay_loan → repay_installment is correct and the XDR-decode test rewrite is good. But re-auditing this against the current contract source surfaced a blocking mismatch on the repayment path:
buildRepayInstallmentTx sends 3 args; the contract takes 4.
// API (creditline.client.ts) — 3 args
contract.call('repay_installment', userArg, loanIdArg, amountArg)
// borrower loan_id amount// creditline-contract/src/lib.rs:751 — 4 caller args
pub fn repay_installment(env, borrower: Address, loan_id: u64,
installment_index: u32, amount: i128)Two problems:
- Missing
installment_index: u32— the call omits it entirely. loan_idtype: sent asnativeToScVal(loanId, { type: 'string' }), but the contract expectsu64.
Against the current contract, server.prepareTransaction (simulation) will reject this invocation, so repayments can't be built at all. Against an older deployed build it might pass now but will break the moment the contract is upgraded to the current source (which the merged waterfall PR #60 requires via upgrade()).
Before this can merge:
- Add
installment_index— the API needs to determine which installment is being paid from the loan's schedule and pass it asu32. - Encode
loan_idasu64(nativeToScVal(BigInt(loanId), { type: 'u64' })or equivalent), notstring. - Verify the deployed testnet
repay_installmentsignature and confirm the API matches it (there's a known repo-vs-deployment gap on the contracts).
The naming half of this PR is right; the on-chain call shape is not. Happy to re-review once the arg/type are aligned.
Fix repayment function name mismatch
Problem
The XDR builder (
creditline.client.ts) builds transactions usingrepay_installmentbut the transaction status checker was looking forrepay_loan. This mismatch meant the follow-up loan balance deduction never triggered after successful on-chain repayments — loans appeared unpaid indefinitely.Root Cause
The function name was changed in one place but not the other during development, as documented in ISSUES.md.
Changes
src/jobs/transaction-status-checker/transaction-status-checker.service.tsrepay_installmentinstead ofrepay_loansrc/stellar/contracts/clients/creditline.client.tssrc/modules/loans/loans.controller.tssrc/modules/loans/dto/loan-payment-response.dto.tstest/unit/stellar/contract-function-name.spec.tsVerification
npm run buildpassesnpm test— 25 suites, 290 tests passCloses #62