feat(tree-escrow): dead tree replacement - sponsor can request replanting#1
Closed
arandomogg wants to merge 1 commit into
Closed
feat(tree-escrow): dead tree replacement - sponsor can request replanting#1arandomogg wants to merge 1 commit into
arandomogg wants to merge 1 commit into
Conversation
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>
Owner
Author
|
Reopening against upstream Farm-credit/stellar-app-os:main. |
Idrhas
pushed a commit
that referenced
this pull request
Jun 29, 2026
…ng-region-map-2 feat: wire live privacy-preserving region map
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 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:verify_dead(farmer, death_proof)— admin-only. Attests that a planted tree died. Moves the escrowPlanted → Deadand records the death proof. No tokens move; the un-released balance (Tranche 2) stays locked to back the replant. Rejected if the escrow is notPlanted, or if nothing remains in escrow to fund a replant.request_replant(farmer)— authorized by the original donor (sponsor). Requires statusDead. Restarts the survival cycle for free: status returns toPlanted,planted_atresets to now (fresh 6-month clock), survival fields clear, andreplant_countincrements. No funds are required or moved.verify_survivalthen 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
EscrowStatus::Deadvariant.EscrowRecordgainsdeath_proof: BytesN<32>andreplant_count: u32; both deposit paths initialize them.verify_deadandrequest_replantentrypoints + events (dead,replant).BatchSlotliterals were missing thegift_recipientfield), so the crate's test suite builds again.Tests
8 new tests; full suite is green (36 passed, 0 failed):
verify_deadrejected before planting and after completionreplant_countrequest_replantrejected when the tree is not marked deadCompatibility
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