feat(contracts): implement virtual yield accrual logic#893
Open
Ebenezer199914 wants to merge 1 commit into
Open
feat(contracts): implement virtual yield accrual logic#893Ebenezer199914 wants to merge 1 commit into
Ebenezer199914 wants to merge 1 commit into
Conversation
- Add accrued_yield: i128 field to Plan struct - Add compute_accrued_yield() private helper (APR formula, integer arithmetic) - ping() accrues yield since last_ping before resetting the timer - trigger_payout() distributes principal + accrued_yield to beneficiaries - reclaim() returns principal + accrued_yield to owner - get_plan() projects pending yield virtually without writing to storage - Add 9 yield-specific tests covering all paths Closes Fracverse#831
|
@Ebenezer199914 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
|
@Ebenezer199914 |
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
Fixes #831 — [Contracts] Implement Virtual Yield Accrual Logic
Implements fully on-chain virtual yield accrual for the Soroban inheritance contract. Yield is computed using an APR formula and accrued lazily (at ping time) or projected virtually (at read time) without external vault interactions.
Changes
lib.rsPlanstruct: Addedaccrued_yield: i128field (initialised to0on plan creation).SECS_PER_YEARconstant:31_536_000seconds used for APR → per-second conversion.compute_accrued_yield(principal, rate_bps, elapsed_secs): Private helper implementingprincipal * rate_bps * elapsed / (10_000 * SECS_PER_YEAR)with saturating arithmetic.ping(): Accrues yield since last ping intoplan.accrued_yieldbefore resettinglast_ping.trigger_payout(): Finalises pending yield at claim time; distributesprincipal + accrued_yieldacross beneficiaries.reclaim(): Finalises pending yield and transfersprincipal + accrued_yieldback to the owner.get_plan(): Projects pending yield since last ping into the returned struct without writing to storage (pure read).test.rsNine new yield-specific tests:
test_yield_not_accrued_when_disabledearn_yield=falsekeepsaccrued_yield=0test_yield_accrues_over_one_yeartest_yield_zero_at_creationt=0test_ping_accrues_yieldtest_ping_does_not_accrue_yield_when_disabledtest_multiple_pings_accumulate_yieldtest_trigger_payout_includes_yieldtest_reclaim_includes_yieldtest_get_plan_projects_yield_without_persistingget_planis idempotent / pureCI
#[allow]attributes preserved).rustfmt-formatted.