feat(contract): implement trigger_payout liveness check and claimable… - #1007
Open
Faromzy wants to merge 1 commit into
Open
feat(contract): implement trigger_payout liveness check and claimable…#1007Faromzy wants to merge 1 commit into
Faromzy wants to merge 1 commit into
Conversation
… transition - Rewrite trigger_payout as a self-contained lifecycle entry point - Step 1: check current_time > last_ping + grace_period; return InactivityPeriodNotMet if grace period has not elapsed - Step 2: on first call past deadline, set plan.is_active = false, write ClaimStatus(owner) = current_time, emit Claimable event; reuse existing ClaimStatus timestamp on subsequent calls so the timelock window is never reset - Step 3: if timelock has not elapsed, return Ok(()) to persist the claimable state on-chain (returning an error would roll back Soroban storage writes); once timelock passes, distribute tokens pro-rata with dust absorbed by the last beneficiary - Add 6 new tests covering: timer not met, exact deadline, two-call flow (marks claimable then pays after timelock), zero-timelock single-call flow, repeated calls do not extend timelock, and plan-not-found - Update 4 existing tests whose assertions were tied to the old PayoutNotTriggered / TimelockNotExpired return paths
|
@Faromzy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
@Faromzy |
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.
feat(contract): implement trigger_payout liveness check and claimable state
transition
Summary
Rewrites trigger_payout in the Soroban inheritance contract to own the full
payout lifecycle internally, eliminating the need for callers to manually call
claim() before triggering a payout.
Changes
contracts/inheritance-contract/src/lib.rs
trigger_payout now executes three sequential steps in a single call:
grace_period. Returns Error::InactivityPeriodNotMet if the owner is still
considered alive.
plan.is_active = false, writes ClaimStatus(owner) = current_time to persistent
storage, and emits a Claimable event. On repeat calls the original claim_time
is reused so the timelock window is never extended. When the timelock has not
yet elapsed, the function returns Ok(()) (not an error) so that the state
changes are committed on-chain — returning an error would cause Soroban to
roll back all storage writes, losing the transition.
tokens are distributed pro-rata to all beneficiaries using their
allocation_bps. Integer-division dust is absorbed by the last beneficiary so
the contract never retains stranded tokens.
contracts/inheritance-contract/src/test.rs
greater-than required), two-call flow (marks claimable → pays after timelock),
zero-timelock single-call flow, repeated calls do not extend timelock, and
plan-not-found.
PayoutNotTriggered / TimelockNotExpired error paths that no longer apply.
Call pattern
// First call — grace period elapsed, timelock not yet done.
// Plan is marked claimable (is_active = false, ClaimStatus written). Returns
Ok.
contract.trigger_payout(owner);
// … wait timelock_duration seconds …
// Second call — timelock elapsed, full payout executed.
contract.trigger_payout(owner);
If timelock_duration is zero, the plan transitions to claimable and pays out
in the same call.
Test results
test result: ok. 134 passed; 0 failed (unit tests)
test result: ok. 5 passed; 0 failed (property tests)
closes #918