feat: add per-holder dividend accrual ledger with global index - #864
Merged
thlpkee20-wq merged 2 commits intoAug 31, 2026
Merged
Conversation
Introduces a report-time accrual ledger that snapshots each holder's pending dividend after every accepted report_revenue call, removing the need to re-walk all revenue periods on partial claims and re-claims. Storage ------- - DataKey2::ReportAccPerShareE18(OfferingId): monotonically increasing global accumulator advanced by report_revenue using delta = normalized_amount * 1e18 / total_share_bps. O(1) write per report. - DataKey2::HolderReportLedger(OfferingId, Address): per-holder checkpoint storing (last_report_acc_e18, accrued_owed). Settled lazily on every set_holder_share call so the frozen balance is an immutable baseline. Behaviour --------- - report_revenue (initial + override, non-event-only): advances ReportAccPerShareE18 and emits rpt_acc_u for indexer reconciliation. - set_holder_share: settles pending accrual at the old share before overwriting it, so mid-period share changes capture the correct split. - get_holder_pending_report_accrual: O(1) read returning accrued_owed + unsettled delta since last settlement. Backward compatibility ---------------------- The existing deposit-based claim path (PeriodRevenue, AccPerShareAtIndex, get_claimable, get_holder_accrued_unclaimed) is unchanged. The new ledger runs in parallel and tracks report-time state independently. Storage layout -------------- Both new DataKey2 variants are registered in tools/storage_layout_schema.rs and docs/STORAGE_LAYOUT.json to keep the storage drift check clean. Tests ----- 19 focused tests in src/test_dividend_accrual_ledger.rs covering: happy paths, share-change settlement, event emission, auth boundaries, O(1) gas verification, backward compatibility, and boundary/edge inputs.
|
@praizeD10 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! 🚀 |
5 tasks
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.
closes #855
Introduces a report-time accrual ledger that snapshots each holder's pending dividend after every accepted report_revenue call, removing the need to re-walk all revenue periods on partial claims and re-claims.
Storage
Behaviour
Backward compatibility
The existing deposit-based claim path (PeriodRevenue, AccPerShareAtIndex, get_claimable, get_holder_accrued_unclaimed) is unchanged. The new ledger runs in parallel and tracks report-time state independently.
Storage layout
Both new DataKey2 variants are registered in tools/storage_layout_schema.rs and docs/STORAGE_LAYOUT.json to keep the storage drift check clean.
Tests
19 focused tests in src/test_dividend_accrual_ledger.rs covering: happy paths, share-change settlement, event emission, auth boundaries, O(1) gas verification, backward compatibility, and boundary/edge inputs.