Skip to content

feat(tree-escrow): dead tree replacement - sponsor can request replanting#1

Closed
arandomogg wants to merge 1 commit into
mainfrom
feat/489-dead-tree-replacement
Closed

feat(tree-escrow): dead tree replacement - sponsor can request replanting#1
arandomogg wants to merge 1 commit into
mainfrom
feat/489-dead-tree-replacement

Conversation

@arandomogg

Copy link
Copy Markdown
Owner

Summary

Implements dead tree replacement for the single-donor escrow flow in contracts/tree-escrow. When a planted tree is verified dead, the original sponsor can trigger a free replant that is backed by the retained escrow balance — no new deposit is required, exactly as the issue describes.

How it works

The single-donor lifecycle previously was: Funded → Planted (75% released) → Completed (remaining 25% released on survival). This PR inserts a death/replant detour:

Planted ──verify_dead──▶ Dead ──request_replant──▶ Planted (fresh survival clock)
  • verify_dead(farmer, death_proof) — admin-only. Attests that a planted tree died. Moves the escrow Planted → Dead and records the death proof. No tokens move; the un-released balance (Tranche 2) stays locked to back the replant. Rejected if the escrow is not Planted, or if nothing remains in escrow to fund a replant.
  • request_replant(farmer) — authorized by the original donor (sponsor). Requires status Dead. Restarts the survival cycle for free: status returns to Planted, planted_at resets to now (fresh 6-month clock), survival fields clear, and replant_count increments. No funds are required or moved.
  • verify_survival then releases the remainder once the replanted tree survives 6 months — unchanged.

The replant is "free" to the sponsor because the original escrow balance continues to back the outcome; the death/replant cycle can repeat if a replanted tree also dies.

Changes

  • New EscrowStatus::Dead variant.
  • EscrowRecord gains death_proof: BytesN<32> and replant_count: u32; both deposit paths initialize them.
  • New verify_dead and request_replant entrypoints + events (dead, replant).
  • Fixes a pre-existing test compile break (BatchSlot literals were missing the gift_recipient field), so the crate's test suite builds again.

Tests

8 new tests; full suite is green (36 passed, 0 failed):

  • marking dead retains funds and moves no tokens
  • verify_dead rejected before planting and after completion
  • replant restarts the survival cycle and costs the sponsor nothing
  • replanted tree releases the remainder on survival
  • replant resets the 6-month survival clock
  • repeated death/replant cycles increment replant_count
  • request_replant rejected when the tree is not marked dead

Compatibility

Scoped entirely to tree-escrow. Additive entrypoints and additive struct fields; existing flows (deposit, planting, survival, refund, co-funded, oracle) are unchanged and still pass.

Closes Farm-credit#489

Adds a free replant path to the single-donor escrow flow. When a planted
tree is verified dead by the admin, the sponsor can trigger a replant that
is backed by the retained escrow balance, so no new funds are required.

- verify_dead: admin attests a planted tree dead; escrow moves Planted to
  Dead and keeps the un-released balance. Rejected once nothing remains.
- request_replant: original donor restarts the survival cycle for free;
  escrow returns to Planted with a fresh 6-month clock and replant_count++.
- EscrowRecord gains death_proof and replant_count; new Dead status.
- verify_survival then releases the remainder once the replant survives.

Also fixes a pre-existing test compile break (BatchSlot.gift_recipient).
Adds 8 tests covering the death/replant lifecycle, clock reset, repeated
replants, and guard conditions.

Closes Farm-credit#489

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@arandomogg

Copy link
Copy Markdown
Owner Author

Reopening against upstream Farm-credit/stellar-app-os:main.

@arandomogg arandomogg closed this Jun 27, 2026
Idrhas pushed a commit that referenced this pull request Jun 29, 2026
…ng-region-map-2

feat: wire live privacy-preserving region map
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.

feat(contract): Dead tree replacement - sponsor can request replanting

1 participant