Skip to content

feat(contracts): implement points ledger with FIFO spend and expiry (#402, #403) - #415

Closed
nuvoraxis wants to merge 1 commit into
MindFlowInteractive:mainfrom
nuvoraxis:feat/402-403-points-ledger-fifo-spend-expiry
Closed

nuvoraxis wants to merge 1 commit into
MindFlowInteractive:mainfrom
nuvoraxis:feat/402-403-points-ledger-fifo-spend-expiry

Conversation

@nuvoraxis

Copy link
Copy Markdown

Summary of Changes

This Pull Request provides a comprehensive, production-grade Soroban smart contract for the Achievement Points Ledger lifecycle across Stages 1 and 2, fulfilling all acceptance criteria for both #402 and #403:

  1. Points Ledger & Authorized Earning (Stage 1 - Achievement Points Ledger #402):

    • Access-controlled point issuance: only contract admin and authorized game contracts can award points.
    • Comprehensive audit trail recording player, amount, remaining balance, reason code, earn timestamp, expiration timestamp, and calling contract address.
    • Strict invariant: total cumulative points earned equals the sum of all history entries.
  2. FIFO Spending & Expiration Policy (Stage 2 - Achievement Points: Spend and Expiry #403):

    • spend function with balance check for player in-game purchases.
    • Tracks duration-based expiration per earn entry.
    • Strictly enforces First-In First-Out (FIFO) consumption of points, consuming from the oldest unexpired entries first.
    • Excludes expired points from available spendable balance.
    • Rejects spending when requested amount exceeds available unexpired points balance (InsufficientBalance error).
  3. Testing & Tooling:

    • 4/4 unit tests in src/test.rs passing with 100% success (covering authorized earning, balance invariant, strict FIFO consumption order, expiration exclusion, and overspend protection).
    • Clean workspace integration in root Cargo.toml.
    • Architectural documentation in contracts/points_ledger/README.md.

Closes #402
Closes #403

…indFlowInteractive#402, MindFlowInteractive#403)

- Add modular Soroban smart contract in contracts/points_ledger
- Implement points balance and full historical ledger structure
- Support authorized caller access control (admin and whitelisted game contracts)
- Implement earn and earn_with_expiry recording amount, player, caller, reason code, and expiry timestamp
- Implement spend function with strict First-In First-Out (FIFO) consumption of oldest unexpired points
- Exclude expired points from available balance and reject spending when exceeding unexpired balance
- Expose read functions for get_balance, get_total_earned, and get_history
- Add unit test suite in src/test.rs covering authorized earning, balance invariant, FIFO spend order, and expiration exclusion
- Add README.md documentation and workspace entry in Cargo.toml

Closes MindFlowInteractive#402
Closes MindFlowInteractive#403
@Mkalbani Mkalbani closed this Nov 22, 2026
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.

Achievement Points: Spend and Expiry Achievement Points Ledger

2 participants