Skip to content

feat(contract): implement trigger_payout liveness check and claimable… - #1007

Open
Faromzy wants to merge 1 commit into
Fracverse:masterfrom
Faromzy:feat/trigger-payout-liveness-check
Open

feat(contract): implement trigger_payout liveness check and claimable…#1007
Faromzy wants to merge 1 commit into
Fracverse:masterfrom
Faromzy:feat/trigger-payout-liveness-check

Conversation

@Faromzy

@Faromzy Faromzy commented Jul 27, 2026

Copy link
Copy Markdown

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:

  1. Liveness check — verifies current_ledger_timestamp > last_ping +
    grace_period. Returns Error::InactivityPeriodNotMet if the owner is still
    considered alive.
  2. Claimable transition — on the first call past the deadline, sets
    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.
  3. Timelock + distribution — once claim_time + timelock_duration has elapsed,
    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

  • Added 6 new tests covering: timer not met, timer at exact deadline (strictly
    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.
  • Updated 4 existing tests whose assertions were tied to the old
    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

… 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
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

@ONEONUORA

Copy link
Copy Markdown
Contributor

@Faromzy
Pls run cargo fmt, clippy and test

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] Issue #7: Implement trigger_payout Verification

2 participants