Skip to content

feat: add per-holder dividend accrual ledger with global index - #864

Merged
thlpkee20-wq merged 2 commits into
RevoraOrg:masterfrom
praizeD10:feat/dividend-accrual-ledger
Aug 31, 2026
Merged

feat: add per-holder dividend accrual ledger with global index#864
thlpkee20-wq merged 2 commits into
RevoraOrg:masterfrom
praizeD10:feat/dividend-accrual-ledger

Conversation

@praizeD10

Copy link
Copy Markdown

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

  • 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.

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

drips-wave Bot commented Aug 29, 2026

Copy link
Copy Markdown

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

Learn more about application limits

@thlpkee20-wq
thlpkee20-wq merged commit 84153bf into RevoraOrg:master Aug 31, 2026
2 of 3 checks passed
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.

Add dividend accrual ledger so unclaimed revenue compounds per-holder until claim

2 participants