Skip to content

Settlement flow: funded to settled, pro-rata investor returns #9

@Jayrodri088

Description

@Jayrodri088

Context

When the debtor pays, investors realize yield. Until automated Soroban/oracle settlement is fully wired, the backend still needs a correct, auditable settlement path that closes the invoice and investments and records returns.

Contributor workflow

  • Apply on Drips before opening a PR: Claim this issue through the Drips platform before you open a pull request. Unsolicited PRs from unassigned contributors may be closed without review.
  • ETA required: Your application must include an ETA for when you will open the first draft PR.
  • Draft PR within 24 hours: If a draft PR is not linked on this issue within 24 hours of assignment, maintainers may unassign you so someone else can take the issue.

Goals

  • Implement settlement that transitions:
    • Invoice: fundedsettled (reject invalid states with stable error.code).
    • Investments: confirmedsettled with actual_return populated.
  • Pro-rata returns: Distribute settlement proceeds across investors by their committed amounts (document formula; handle rounding to last investor or fixed precision—state choice).
  • Create or update Transaction rows of type payment where it aids audit (link to users/invoices as your schema allows).
  • Idempotency: Calling settlement twice must not double-pay in DB terms.

MVP input (choose and document)

  • Either authenticated admin endpoint, or seller endpoint with strict checks, accepting e.g. paidAmount, stellarTxHash (optional), settledAt.
  • Clearly label in code comments / PR that this is an MVP bridge until on-chain settlement drives status.

Acceptance criteria

  • Illegal transitions return 400 with stable codes.
  • Pro-rata math tests cover at least 2 investors + rounding edge case.
  • Idempotent settlement verified by test.
  • npm run type-check passes; tests pass.

PR submission requirements

  • CI: All GitHub Actions workflow runs for this PR must pass (green) before merge; failing checks block merge.
  • PR description must include: Closes #9.
  • PR explains how this will be replaced or augmented by Soroban events later (short paragraph).
  • List who is authorized to call settlement in this MVP (role / user type).

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programfeatureNew capability

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions