Skip to content

Implement two-step repayment flow with buildRepaymentXdr() and submit…#51

Open
deslawson wants to merge 1 commit into
StepFi-app:mainfrom
deslawson:core-implement-installment-repayment-XDR-builder-#33
Open

Implement two-step repayment flow with buildRepaymentXdr() and submit…#51
deslawson wants to merge 1 commit into
StepFi-app:mainfrom
deslawson:core-implement-installment-repayment-XDR-builder-#33

Conversation

@deslawson

Copy link
Copy Markdown
Contributor

🔗 Related Issue

Closes #33


🔖 Title

Implement two-step repayment flow with buildRepaymentXdr() and submitRepayment()


📝 Description

Adds a two-step loan repayment flow that replaces the broken repay_loan contract call with the correct repay_installment() function. Step 1 — Build unsigned XDR (POST /loans/:loanId/pay):

  • Validates loan ownership, active status, and payment amount against remaining balance
  • Calls repay_installment() on the creditline contract via CreditLineContractClient.buildRepayLoanTx()
  • Returns unsigned XDR + payment preview Step 2 — Submit signed XDR (POST /loans/:loanId/repay):
  • Accepts a signed XDR in the request body
  • Submits to Horizon and polls for ledger confirmation (up to ~60s)
  • Returns { transactionHash } on success New files: src/modules/blockchain/blockchain.module.ts, src/modules/blockchain/blockchain.service.ts Modified files: creditline.client.ts, loans.service.ts, loans.controller.ts, loans.module.ts, app.module.ts

🔄 Changes Made

  • I Fixed contract function name — Changed creditline.client.ts to call repay_installment() instead of the non-existent repay_loan()
  • Added buildRepaymentXdr() — New method in loans.service.ts that validates loan state (ownership, active status, balance) and returns an unsigned XDR for repay_installment()
  • Added submitRepayment() — New method in blockchain.service.ts that submits a signed XDR to Horizon and polls for ledger confirmation before returning the transaction hash
  • Added POST /loans/:loanId/repay endpoint — New controller endpoint accepting { xdr: string } to complete the two-step flow
  • Created BlockchainModule — New self-contained module exporting BlockchainService, imported by LoansModule and AppModule

📸 Screenshots (if applicable)


🗒️ Additional Notes

Closed #33

…Repayment()

Adds a two-step loan repayment flow that replaces the broken repay_loan contract call with the correct repay_installment() function.
Step 1 — Build unsigned XDR (POST /loans/:loanId/pay):
- Validates loan ownership, active status, and payment amount against remaining balance
- Calls repay_installment() on the creditline contract via CreditLineContractClient.buildRepayLoanTx()
- Returns unsigned XDR + payment preview
Step 2 — Submit signed XDR (POST /loans/:loanId/repay):
- Accepts a signed XDR in the request body
- Submits to Horizon and polls for ledger confirmation (up to ~60s)
- Returns { transactionHash } on success
New files: src/modules/blockchain/blockchain.module.ts, src/modules/blockchain/blockchain.service.ts
Modified files: creditline.client.ts, loans.service.ts, loans.controller.ts, loans.module.ts, app.module.ts

Closed StepFi-app#33
@EmeditWeb

Copy link
Copy Markdown
Member

@deslawson fix CI issues

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.

core: implement installment repayment XDR builder

2 participants