Skip to content

Contract staking-rewards: add reward projection preview and epoch summary accessor #496

@CMI-James

Description

@CMI-James

Background

Contributors working on staking and loyalty reward flows need lightweight read endpoints that expose reward math context without requiring clients to rebuild epoch-level accounting off-chain.

Feature Focus

Add reward projection and epoch summary accessors to the staking rewards contract.

Where to Implement (Exact Targets)

  • contracts/staking-rewards/src/lib.rs
  • contracts/staking-rewards/src/storage.rs
  • contracts/staking-rewards/src/types.rs
  • contracts/staking-rewards/src/test.rs

What to Implement

  • Add a view that returns the current reward projection for a staker based on stake amount, epoch state, and accrued but unclaimed rewards.
  • Add a summary accessor for active epoch metadata, total distributed rewards, and pending carry-over.
  • Ensure returned values are deterministic and safe for frontend polling.
  • Keep accessor behavior resilient when no epoch has started yet.

Interface / Endpoint / Method Details

  • Expose read-only methods with explicit return types for projection and epoch summary payloads.
  • Reuse existing storage keys where possible instead of duplicating aggregate state.
  • Document any rounding behavior or zero-value fallback conventions in contract comments and generated docs.

Acceptance Criteria

  • Staking UI can fetch both reward preview and epoch summary in one round-trip pattern.
  • Accessors do not mutate contract state.
  • Empty-state responses are well-defined and tested.

Required Tests

  • Unit tests covering active epoch, empty epoch, and partially claimed reward scenarios.
  • Assertions for deterministic output ordering and expected numeric conversions.

Definition of Done

  • New accessors are implemented, documented, and covered by tests.
  • Generated contract docs reflect the new public interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ContractSmart contract workMediumMedium prioritySorobanSoroban-specific workStellar WaveStellar Wave initiativeenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions