Skip to content

feat(production-escrow): implement harvest reporting, settlement calculation, and failed campaign refunds#27

Merged
Dannyswiss1 merged 1 commit into
Cylo-Traders:masterfrom
sanmipaul:feat/harvest-settlement-refunds
Jun 20, 2026
Merged

feat(production-escrow): implement harvest reporting, settlement calculation, and failed campaign refunds#27
Dannyswiss1 merged 1 commit into
Cylo-Traders:masterfrom
sanmipaul:feat/harvest-settlement-refunds

Conversation

@sanmipaul

@sanmipaul sanmipaul commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements all three deliverables for the Production Escrow contract:

  • Harvest Reportingreport_harvest now requires farmer (or admin) authentication, stores a HarvestRecord (farmer, outcome, timestamp, ledger_sequence), and transitions campaign status to Harvested
  • Settlement Calculationsettle_campaign is admin-only, requires Harvested status, splits escrowed funds between a farmer payout (transferred on-chain) and an investor returnable pool; investors claim their pro-rata share via the new claim_return function
  • Failed Campaign Refundsmark_failed (admin-only) marks Active/Funding/Funded campaigns as Failed and moves all escrowed funds into the refundable pool; claim_refund is extended to cover Failed campaigns and now executes the actual token transfer back to the investor

Key design decisions

  • escrow_held now deducts returnable alongside released and refundable to prevent double-spending across all paths
  • Harvested and Failed are added as terminal-adjacent statuses; both block tranche releases via is_terminal
  • settle_campaign transfers the farmer payout immediately on settlement; investors pull their returns via claim_return
  • Contribution is zeroed on claim (for both claim_refund and claim_return) to prevent double claims

Test plan

  • report_harvest sets Harvested status and stores outcome record
  • Unauthorized harvest reporter is rejected
  • settle_campaign panics on non-Harvested campaign
  • Proportional investor returns: investor1 (60%) and investor2 (40%) receive correct shares
  • Full farmer payout leaves zero returnable; claim_return is blocked
  • Settlement cannot execute twice
  • mark_failed sets Failed status and correct refundable balance
  • Investors receive full tokens back after mark_failedclaim_refund
  • Double refund is blocked
  • claim_refund is blocked for Active/Funded/Settled campaigns
  • All existing 52 tests pass (zero regressions)

Closes #4

… 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
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.

[Contract] Implement Harvest Reporting, Settlement Calculation, and Implement Refunds for Failed Campaigns

2 participants