Skip to content

feat: add creator brand loyalty program on-chain (#875) - #910

Merged
Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
jacobjacobb4242:feat/issue-875-creator-brand-loyalty-program
Sep 30, 2026
Merged

Kingsman-99 merged 2 commits into
Stellar-split:mainfrom
jacobjacobb4242:feat/issue-875-creator-brand-loyalty-program

Conversation

@jacobjacobb4242

Copy link
Copy Markdown

Issue #875 — Add creator brand loyalty program on-chain

Adds a new brand_loyalty_ext.rs module implementing a fully on-chain
per-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 formula amount × points_per_unit / POINTS_SCALE (POINTS_SCALE = 1 000 000). Callable by the creator after pay.
  • redeem_loyalty_points(payer, creator, points_to_redeem) — burns points and returns a discount amount in token units, capped at max_discount_bps / 10 000 of the raw discount.

Read-only:

  • get_loyalty_program(creator) → Option<LoyaltyProgram>
  • get_loyalty_points(creator, payer) → i128
  • is_loyalty_discount_enabled(invoice_id) → bool

Events

Topic Data
(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 LoyaltyKey enum in persistent storage:

  • Program(creator) — LoyaltyProgram config.
  • Points(creator, payer) — i128 accumulated balance.
  • DiscountEnabled(invoice_id) — bool flag.

New type

LoyaltyProgram { creator, points_per_unit, max_discount_bps, active }

Tests

8 unit tests:

  • Init and get program
  • Double init rejected
  • Update program
  • Credit and read points
  • Redeem points (checks formula + cap)
  • Redeem more than balance rejected
  • Enable loyalty discount flag
  • Default points are zero
  • Excessive discount bps rejected

Files changed

File Change
contracts/split/src/brand_loyalty_ext.rs New
contracts/split/src/lib.rs Added mod brand_loyalty_ext;

Closes #875

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

drips-wave Bot commented Sep 30, 2026

Copy link
Copy Markdown

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

Learn more about application limits

@Kingsman-99
Kingsman-99 merged commit 6ab6be6 into Stellar-split:main Sep 30, 2026
1 of 4 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 creator brand loyalty program on-chain

2 participants