Referral System
xendune implements a two-tier referral system managed by the InviteRegistry contract. Referral rewards are automatically distributed from the platform fee to the seller's invite chain on order settlement.
How It Works
Registration
- New user calls
InviteRegistry.register(inviterAddress)to bind an inviter - InviteRegistry records on-chain: the direct inviter (L1) and the inviter's inviter (L2)
- Each address can only register once (immutable once set)
- Cannot invite yourself, cannot invite a contract address, no circular chains
Reward Distribution
On every order settlement, the business contract transfers the fee into InviteRegistry and calls distributeFee(seller, feeAmount, token):
- Check if the seller has an L1 inviter → transfer L1 reward
- Check if the seller has an L2 inviter → transfer L2 reward
- Remaining fee distributed to the platform via PlatformFeeSplitter (3-way split)
Note: Rewards are based on the seller's invite chain only — the buyer's inviter is not involved.
Reward Rates
| Tier | Rate (of platform fee) | Source |
|---|---|---|
| L1 (seller's direct inviter) | 20% | PlatformSettings.level1Rate = 2000 |
| L2 (seller's second-tier inviter) | 10% | PlatformSettings.level2Rate = 1000 |
| Platform | 70% | PlatformSettings.platformRate = 7000 |
The three rates must sum to 10000 (100%). The owner can adjust via setInviteRates(), but the sum is always validated.
Fee Flow Example
For a 100 USDT order with 3% platform fee (e.g., physical or virtual goods):
- Platform fee: 3 USDT
- Seller's L1 inviter reward: 0.60 USDT (3 USDT × 20%)
- Seller's L2 inviter reward: 0.30 USDT (3 USDT × 10%)
- Platform net income: 2.10 USDT (distributed via PlatformFeeSplitter 3-way split)
- Seller receives: 97 USDT
If the seller has no inviter, the corresponding reward goes to the platform. If L2 does not exist, the L2 share also goes to the platform.
Security
- Referral relationships are immutable once set
- Rewards distributed atomically during settlement
- If a reward transfer fails, funds are routed through PlatformFeeSplitter (built-in try/catch, falls back to platform wallet on failure)
- Circular invite chain check: validated at registration time