feat(production-escrow): implement harvest reporting, settlement calculation, and failed campaign refunds#27
Merged
Dannyswiss1 merged 1 commit intoJun 20, 2026
Conversation
… investor returns, and failed campaign refunds Closes Cylo-Traders#4 - report_harvest: requires farmer/admin auth, stores HarvestRecord, transitions campaign to Harvested - settle_campaign: admin-only, requires Harvested status, splits escrow between farmer payout and investor returnable pool, transfers tokens to farmer - claim_return: investors claim pro-rata share of returnable pool after settlement, with token transfer - mark_failed: admin marks Active/Funding/Funded campaigns as Failed, making full escrow refundable - claim_refund: extended to cover Failed campaigns in addition to Resolved; now executes token transfer back to investor - escrow_held: updated to deduct returnable to prevent double-spending - CampaignStatus: added Harvested and Failed variants; both block tranche releases as terminal states - HarvestRecord type and DataKey::HarvestRecord for persistent harvest outcome storage - 52 tests covering full and partial settlement proportional returns, failed campaign refund flows, double-claim prevention, and all event emissions
68ecfbe to
fd34b4f
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
Implements all three deliverables for the Production Escrow contract:
report_harvestnow requires farmer (or admin) authentication, stores aHarvestRecord(farmer, outcome, timestamp, ledger_sequence), and transitions campaign status toHarvestedsettle_campaignis admin-only, requiresHarvestedstatus, splits escrowed funds between a farmer payout (transferred on-chain) and an investor returnable pool; investors claim their pro-rata share via the newclaim_returnfunctionmark_failed(admin-only) marks Active/Funding/Funded campaigns asFailedand moves all escrowed funds into the refundable pool;claim_refundis extended to coverFailedcampaigns and now executes the actual token transfer back to the investorKey design decisions
escrow_heldnow deductsreturnablealongsidereleasedandrefundableto prevent double-spending across all pathsHarvestedandFailedare added as terminal-adjacent statuses; both block tranche releases viais_terminalsettle_campaigntransfers the farmer payout immediately on settlement; investors pull their returns viaclaim_returnclaim_refundandclaim_return) to prevent double claimsTest plan
report_harvestsetsHarvestedstatus and stores outcome recordsettle_campaignpanics on non-Harvested campaignclaim_returnis blockedmark_failedsetsFailedstatus and correct refundable balancemark_failed→claim_refundclaim_refundis blocked for Active/Funded/Settled campaignsCloses #4