feat: add creator brand loyalty program on-chain (#875) - #910
Merged
Kingsman-99 merged 2 commits intoSep 30, 2026
Merged
Kingsman-99 merged 2 commits into
Kingsman-99 merged 2 commits into
Conversation
Add brand_loyalty_ext.rs implementing a per-creator loyalty points program where payers earn points proportional to their payment amounts and can redeem them for discounts on future invoices. Entry points: - init_loyalty_program(creator, points_per_unit, max_discount_bps) - update_loyalty_program(creator, points_per_unit, max_discount_bps) - enable_loyalty_discount(creator, invoice_id) - credit_loyalty_points(creator, payer, invoice_id, amount) - redeem_loyalty_points(payer, creator, points_to_redeem) -> i128 - get_loyalty_program(creator) -> Option<LoyaltyProgram> - get_loyalty_points(creator, payer) -> i128 - is_loyalty_discount_enabled(invoice_id) -> bool Points formula: amount * points_per_unit / POINTS_SCALE (1_000_000) Discount capped at max_discount_bps (max 5_000 = 50%) Events: loy_init, loy_upd, loy_crd, loy_rdm Storage: local LoyaltyKey enum in persistent storage Tests: 8 unit tests covering all paths and guard conditions Closes Stellar-split#875
|
@jacobjacobb4242 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.
Issue #875 — Add creator brand loyalty program on-chain
Adds a new
brand_loyalty_ext.rsmodule implementing a fully on-chainper-creator loyalty points program. Payers accumulate points proportional
to payments and can redeem them for token-unit discounts on future invoices.
Core functionality
Program lifecycle (creator):
init_loyalty_program(creator, points_per_unit, max_discount_bps)— one-time setup;points_per_unit ≥ 1,max_discount_bps ∈ [1, 5 000].update_loyalty_program(creator, points_per_unit, max_discount_bps)— update params after creation.enable_loyalty_discount(creator, invoice_id)— opt a specific invoice into the loyalty discount program.Points lifecycle:
credit_loyalty_points(creator, payer, invoice_id, amount)— awards points using the formulaamount × points_per_unit / POINTS_SCALE(POINTS_SCALE = 1 000 000). Callable by the creator afterpay.redeem_loyalty_points(payer, creator, points_to_redeem)— burns points and returns a discount amount in token units, capped atmax_discount_bps / 10 000of the raw discount.Read-only:
get_loyalty_program(creator)→Option<LoyaltyProgram>get_loyalty_points(creator, payer)→i128is_loyalty_discount_enabled(invoice_id)→boolEvents
(split, loy_init)creator(split, loy_upd)creator(split, loy_crd, invoice_id)(payer, points)(split, loy_rdm)(payer, creator, points_redeemed, discount)Storage
Local
LoyaltyKeyenum in persistent storage:Program(creator)—LoyaltyProgramconfig.Points(creator, payer)—i128accumulated balance.DiscountEnabled(invoice_id)—boolflag.New type
LoyaltyProgram { creator, points_per_unit, max_discount_bps, active }Tests
8 unit tests:
Files changed
contracts/split/src/brand_loyalty_ext.rscontracts/split/src/lib.rsmod brand_loyalty_ext;Closes #875