Feature/multi investor factoring payer role#59
Merged
Jayrodri088 merged 7 commits intoStellarState:mainfrom Mar 27, 2026
Merged
Conversation
…ions - Replace plain subtraction with checked_sub in burn() and burn_from() - Return Overflow error on underflow to prevent edge-case issues - Maintains backward compatibility for valid burn amounts - Improves defensive programming for smart contracts
- Export EscrowStatus from invoice-escrow lib for external use - Fix payment-distributor integration tests with new API signatures - Update test debtor parameters to use payer where record_payment is called - Fix event assertions to match new event signatures - All invoice-escrow tests passing (47/47) - Payment-distributor tests have pre-existing auth issues unrelated to these changes
…uppress clippy warnings
…com:caxtonacollins/SS-contracts into feature/multi-investor-factoring-payer-role
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.
Multi-Investor Factoring with Payer Role Enforcement
Overview
This PR implements four interconnected features for the invoice-escrow contract to support decentralized factoring with multiple investors, explicit discount modeling, and enhanced security through payer role enforcement.
Issues Closed
Closes #29 : Use checked math for invoice-token total_supply on burn
Closes #33 : Enforce correct payer role in invoice-escrow record_payment
Closes #39 : Model factoring discount (face value vs investor purchase price)
Closes #43 : Partial/multi-investor funding (MVP slice)
Key Changes
Issue #29: Checked Math for Burn Operations
checked_sub()inburn()andburn_from()Overflowerror on underflow to prevent edge-case issuesIssue #33: Payer Role Enforcement
debtorfield toEscrowDatato track authorized invoice payerInvalidPayererror typecreate_escrow()to acceptdebtorparameterpayer == debtorcheck inrecord_payment()Issue #39: Factoring Discount Model
face_valuefield: what the debtor owes (amount to be paid at settlement)purchase_pricefield: what investors pay (discount applied here)create_escrow()signature to accept both valuesfund_escrow()to usepurchase_pricefor investor fundingrecord_payment()to settle based onface_valuerefund()to usepurchase_pricefor collateral calculationIssue #43: Multi-Investor Funding MVP
funded_amtfield to track total funding progressfunderfield (MVP: stores primary funder for distribution)FunderAmountstorage key for per-funder trackingfund_escrow()to acceptamountparameter for partial fundingrecord_payment()andrefund()purchase_priceis reachedFundedonly when fully subscribedAPI Changes
create_escrow
Old:
(invoice_id, seller, amount, due_date, payment_token, invoice_token)New:
(invoice_id, seller, debtor, face_value, purchase_price, due_date, payment_token, invoice_token)fund_escrow
Old:
(invoice_id, buyer)New:
(invoice_id, buyer, amount)Test Coverage
Implementation Notes
MVP Design Choice
For the MVP, we support multiple funders with per-address tracking but distribute pro-rata based on contribution. The
funderfield stores the primary funder for backward compatibility with existing tests. Future phases can extend this to track all funders in a list and distribute individually.Pro-Rata Distribution Formula
Fee Application
Fees are calculated on the payment amount (not face_value), ensuring consistent economics:
Backward Compatibility
Future Enhancements