Feat/1045 loyalty rewards contract - #1124
Merged
Calebux merged 1 commit intoJul 26, 2026
Merged
Conversation
wendypetersondev
force-pushed
the
feat/1045-loyalty-rewards-contract
branch
from
July 25, 2026 09:11
0ec763e to
b9fa7a4
Compare
…ewals (Calebux#1045) Add a new `loyalty_rewards` Soroban contract that accrues loyalty points for subscribers who renew on time, with streak tracking and a redeem path against fees. ## Contract mechanics - **accrue(owner, sub_id, renewal_ledger)** — called by the authorised renewal caller after a successful on-time renewal. Awards `BASE_POINTS` (100) + `streak × STREAK_BONUS` (50), with the streak multiplier capped at `MAX_STREAK_BONUS_LEVEL` (20) to bound the max per-renewal award at 1 100 points. - **miss(owner, sub_id)** — called when a renewal is missed or late. Resets the consecutive streak to 0; does not deduct points. - **redeem(owner, amount)** — burns `amount` points from the owner's balance and returns the equivalent fee credit (1 point = 1 credit unit). Enforces a minimum redemption of 100 points. ## Storage layout | Key | Storage tier | Description | |-----|-------------|-------------| | `ConfigKey::Admin` | Persistent | Contract administrator | | `ConfigKey::RenewalCaller` | Persistent | Authorised renewal contract address | | `ConfigKey::Paused` | Persistent | Global pause flag | | `UserKey::Account(addr)` | Instance | Per-user `LoyaltyAccount` struct | ## Errors | Code | Name | Trigger | |------|------|---------| | #1 | NotInitialized | Contract not yet initialised | | #2 | AlreadyInitialized | `init` called twice | | Calebux#3 | Unauthorized | Auth check failed | | Calebux#4 | Paused | Contract is paused | | Calebux#5 | RedeemTooSmall | `amount < MIN_REDEEM` | | Calebux#6 | InsufficientPoints | Balance < requested amount | | Calebux#7 | Overflow | Arithmetic overflow guard | ## Test coverage (35 tests) - init: success + double-init guard - accrue: base points, streak increment, bonus arithmetic, balance accumulation, lifetime points, last-renewal ledger recording - accrue: streak bonus hard-capped at MAX_STREAK_BONUS_LEVEL - miss: streak reset, no point deduction, zero-streak noop, restart after miss - redeem: burns points + returns credit, full-balance drain, total_redeems counter, lifetime_points invariant - redeem error paths: below minimum, insufficient balance, empty account - pause/unpause: accrue / miss / redeem all reject when paused - set_renewal_caller: admin can rotate the caller address - multiple independent users: balances and streaks are isolated - account / streak / balance queries - uninitialized contract guard Closes Calebux#1045
wendypetersondev
force-pushed
the
feat/1045-loyalty-rewards-contract
branch
from
July 25, 2026 09:14
b9fa7a4 to
efac248
Compare
|
@wendypetersondev 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! 🚀 |
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 #1045
Briefly describe what this PR does.
Related Issue
Closes #
Test Plan
Screenshots (if applicable)
Checklist