Memo-based referral / attribution system#200
Open
OluRemiFour wants to merge 1 commit into
Open
Conversation
|
@OluRemiFour 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! 🚀 |
Contributor
Author
|
Done, Close: #200 |
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.
Close: #94
Summary
I have implemented a complete, fully functional, high-performance Memo-Based Referral and Attribution System for TurboLong. The implementation spans the frontend app and a dedicated referrals backend Worker utilizing Cloudflare D1.
No new smart contracts were needed; referrals are attributed via standard text memos attached to token approval / position opening transactions on the Stellar Network, then captured by a lightweight off-chain indexer.
🛠️ Components Implemented
A modular, high-efficiency Cloudflare Worker containing:
D1 Database Schema (src/schema.sql):
referral_codes: maps owner addresses to their generated referral codes.
referral_events: stores tracked deposit transaction records (with unique transaction hashes to prevent double-counting).
REST API Routes (src/index.ts):
POST /referrals/register: registers/verifies code owned by a wallet address.
GET /referrals/code: returns the code associated with an address.
GET /referrals/stats: computes aggregate stats (total referrals, unique depositors), pool breakdowns, and lists recent referred activity.
Cron Indexer (scheduled):
Automatically runs every 15 minutes.
Fetches the latest transactions on the tracked Blend pool contract addresses from the Stellar Horizon API.
Filters transactions containing ref:
text memos, validates the code, and records the deposit event on D1.2. Frontend: index.html & style.css
Navigation Toggles: Added "Refer & Earn" navigation tabs in the desktop top-nav and the mobile sidebar.
Referral Dashboard View (#referral-view):
Gates stats behind wallet connection.
Generates and displays a shareable referral code and link (complete with copy-to-clipboard buttons).
Premium-styled stats cards showing Total Referrals, Unique Depositors, and Active Referrals.
Detailed grid layouts displaying Breakdown by Pool tables and a live Recent Referrals timeline.
Premium HSL dark-theme styling matching TurboLong's elegant visual system.
3. Frontend Logic: main.ts & blend.ts
URL Parameter Extraction: Instantly captures ?ref=
from search parameters on application load and stores it securely in sessionStorage as a pending referral.Deterministic Code Generation: Generates unique, memorable referral codes (REF-<FIRST_4_CHARS>-<RAND_HEX>) for connecting users.
Memo Injection: Updated the protocol's token approval step (buildApproveXdr) to check sessionStorage and append the pending referral code as a standard text memo before transaction signing and submission.
Related Issue
Closes #94
Checks
Notes for Reviewers