Phase 3: own referral system (sats)

- Referral links carry a random 8 character base32 code (rf_<code>)
  built from the bot username from getMe. Old ref_<id> links still work
  but are never shown.
- The reward (REFERRAL_REWARD_SATS, old name REFERRAL_REWARD still read)
  is paid through the ledger once the invited user's first purchase
  settles, once per invited user, never for self-referrals.
- REFERRAL_DAILY_CAP limits what an inviter earns per UTC day; rewards
  above it wait as pending and are paid on a later day by the billing
  loop.
- /referral shows invited, converted, earned and pending, with Share,
  Copy link and QR code buttons. The Mini App Me page mirrors it.
- Migration 00008: users.ref_code (unique) and referral_rewards,
  backfilled from earlier referral credits in the ledger.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Michilis
2026-11-18 20:58:43 +00:00
co-authored by Claude Opus 5.5
parent 123cede7f3
commit f7ceadc462
30 changed files with 945 additions and 148 deletions
+8 -2
View File
@@ -209,8 +209,14 @@ PRICE_SKIP_QUEUE=50
# Top-up and tip amounts offered as buttons.
CREDIT_PACKS=1000,5000,20000
DONATION_AMOUNTS=500,2100,10000
# Credited to the inviter on an invited user's first purchase. 0 turns it off.
REFERRAL_REWARD=200
# --- Referrals (Lightning) ------------------------------------------------------
# Credited to the inviter when somebody they invited settles a first
# Lightning purchase. 0 turns the reward off. (The older name
# REFERRAL_REWARD still works; this one wins when both are set.)
REFERRAL_REWARD_SATS=200
# The most one inviter earns per day (UTC), in sats. Rewards above it wait
# and are paid on a later day. 0 means no cap.
REFERRAL_DAILY_CAP=2000
# --- Rate limits ------------------------------------------------------------
# Links per minute. 0 means no limit.