Rewards System

Overview

The Med.Fun rewards system provides cashback on trading fees through a tier-based multiplier system. Users earn cashback on every trade, with higher tiers receiving increased multipliers based on their trading volume.

How It Works

  1. Trade Tokens: Execute buy or sell trades on the platform

  2. Earn Cashback: Receive percentage of trading fees back

  3. Tier Multipliers: Cashback multiplied by your current tier (1x to 3x)

  4. Track Volume: Trading volume determines your tier

  5. Accumulate: Cashback accumulates as "pending"

  6. Claim: Withdraw accumulated cashback (minimum $1.00)

Database Schema

reward_tiers

Defines tier structure and multipliers.

Column
Type
Nullable
Default
Description

id

uuid

No

gen_random_uuid()

Primary key

tier_name

text

No

-

Tier display name

tier_level

integer

No

-

Tier number (1-5)

min_volume

numeric

No

0

Min volume required

max_volume

numeric

Yes

null

Max volume (null = unlimited)

cashback_multiplier

numeric

No

1.0

Multiplier for cashback

tier_color

text

No

-

UI color code

benefits

jsonb

No

{}

Additional tier benefits

created_at

timestamptz

No

now()

Creation timestamp

Default Tiers:

Tier
Level
Min Volume
Max Volume
Multiplier
Color

Intern

1

$0

$1,000

1.0x

Gray

Resident

2

$1,000

$10,000

1.5x

Blue

Chief Surgeon

3

$10,000

$50,000

2.0x

Purple

Surgical Trader

4

$50,000

$250,000

2.5x

Gold

Doctor of Degeneracy

5

$250,000

3.0x

Rainbow

Constraints:

  • Unique on tier_level

  • Check: cashback_multiplier > 0

RLS Policies:

  • Anyone can view tiers

  • System can manage tiers

user_trading_stats

Tracks user trading activity and current tier.

Column
Type
Nullable
Default
Description

id

uuid

No

gen_random_uuid()

Primary key

user_wallet

text

No

-

User's wallet address

total_volume

numeric

No

0

Lifetime trading volume

total_trades

integer

No

0

Total trade count

current_tier_id

uuid

Yes

null

Current tier ID

lifetime_cashback

numeric

No

0

Total cashback earned

created_at

timestamptz

No

now()

Stats creation

updated_at

timestamptz

No

now()

Last update

Constraints:

  • Unique index on user_wallet

  • Foreign key to reward_tiers(id)

  • Check: total_volume >= 0

  • Check: total_trades >= 0

RLS Policies:

  • Users can view their own stats

  • Users can create their own stats

  • Users can update their own stats

  • System can manage all stats

cashback_earnings

Records individual cashback transactions.

Column
Type
Nullable
Default
Description

id

uuid

No

gen_random_uuid()

Primary key

user_wallet

text

No

-

Earner's wallet

trade_id

uuid

Yes

null

Related trade ID

trade_volume

numeric

No

-

Trade amount

cashback_amount

numeric

No

-

Cashback earned

multiplier

numeric

No

-

Tier multiplier applied

status

text

No

'pending'

pending/claimed

created_at

timestamptz

No

now()

Earned timestamp

claimed_at

timestamptz

Yes

null

Claimed timestamp

Constraints:

  • Foreign key to user_trading_stats(user_wallet)

  • Check: cashback_amount >= 0

  • Check: multiplier > 0

RLS Policies:

  • Users can view their own earnings

  • Users can update their own earnings (claim)

  • System can insert earnings

Reward Tiers

Tier Definitions

Tier 1: Intern

  • Min Volume: $0

  • Max Volume: $999.99

  • Multiplier: 1.0x (base rate)

  • Color: #6B7280 (Gray)

  • Benefits:

    • Access to basic cashback

    • Transaction history

    • Standard support

Tier 2: Resident

  • Min Volume: $1,000

  • Max Volume: $9,999.99

  • Multiplier: 1.5x (+50% boost)

  • Color: #3B82F6 (Blue)

  • Benefits:

    • All Tier 1 benefits

    • Priority transaction processing

    • Email support

Tier 3: Chief Surgeon

  • Min Volume: $10,000

  • Max Volume: $49,999.99

  • Multiplier: 2.0x (+100% boost)

  • Color: #8B5CF6 (Purple)

  • Benefits:

    • All Tier 2 benefits

    • Advanced analytics

    • Custom dashboard

    • Priority support

Tier 4: Surgical Trader

  • Min Volume: $50,000

  • Max Volume: $249,999.99

  • Multiplier: 2.5x (+150% boost)

  • Color: #F59E0B (Gold)

  • Benefits:

    • All Tier 3 benefits

    • API access

    • Custom alerts

    • VIP support channel

Tier 5: Doctor of Degeneracy

  • Min Volume: $250,000+

  • Max Volume: Unlimited

  • Multiplier: 3.0x (+200% boost)

  • Color: linear-gradient(rainbow) (Rainbow)

  • Benefits:

    • All Tier 4 benefits

    • Dedicated account manager

    • Custom fee structures

    • Early access to features

    • Exclusive community access

Tier Progression

Automatic Tier Assignment:

Progress Calculation:

Cashback Calculation

Base Cashback Formula

Example Calculations

Example 1: Intern (1.0x multiplier)

Example 2: Chief Surgeon (2.0x multiplier)

Example 3: Doctor of Degeneracy (3.0x multiplier)

Cashback Tracking

Trading Stats Tracking

Stats Initialization

When a user makes their first trade:

Stats Updates

After each trade:

Tier Upgrade Check

Claiming Cashback

Claim Requirements

  • Minimum Amount: $1.00 USD

  • Status: Must be 'pending'

  • User Action: Manual claim via dashboard

Claim Process

Claim History

Users can view claimed cashback history:

Real-time Updates

Supabase Subscriptions

Trading Stats Updates:

Cashback Earnings Updates:

Frontend Components

useRewards Hook

Location: /src/hooks/useRewards.tsx

Purpose: Manages all rewards-related data and operations

State Management:

Key Functions:

fetchRewardsData:

TradingRewardsDashboard Component

Location: /src/components/TradingRewardsDashboard.tsx

Features:

  • Tabbed interface (Overview, History, Tiers)

  • Current tier display with color coding

  • Cashback summary (pending/claimed)

  • Trading stats (volume, trades)

  • Tier progress bar

  • Claim button

  • Earnings history list

  • All tiers overview

  • Mobile-responsive

UI Structure:

RewardsCard Component

Location: /src/components/RewardsCard.tsx

Purpose: Summary card for quick access

Displayed Data:

  • Current tier name and icon

  • Pending cashback amount

  • Total earned amount

  • "View Details" button

Integration Points

Record Trade Cashback

User Flows

Flow 1: First Trade & Cashback

Flow 2: Tier Upgrade

Flow 3: Claim Cashback

Best Practices

For Developers

1. Always use transactions for multi-step operations:

2. Handle tier upgrades gracefully:

3. Validate cashback calculations:

For Product

1. Tier thresholds encourage growth

  • Each tier ~10x previous tier volume

  • Creates clear progression goals

  • Rewards high-volume traders

2. Minimum claim prevents micro-transactions

  • $1.00 minimum balances network costs

  • Encourages accumulation

  • Reduces support burden

3. Real-time updates build engagement

  • Instant feedback on earnings

  • Progress bars show advancement

  • Tier upgrades feel rewarding

Troubleshooting

Cashback Not Recording

Check:

  1. Does user_trading_stats record exist?

  2. Is current_tier_id set correctly?

  3. Verify cashback calculation logic

  4. Check database triggers/functions

Tier Not Upgrading

Check:

  1. Is total_volume updating correctly?

  2. Verify tier min_volume thresholds

  3. Check tier upgrade logic

  4. Confirm current_tier_id updates

Cannot Claim Cashback

Check:

  1. Is pending balance >= $1.00?

  2. Are earnings in 'pending' status?

  3. Verify wallet connection

  4. Check RLS policies

Performance Considerations

Database Indexes

Caching Strategy

  • Cache tier definitions (rarely change)

  • Fetch user stats on demand

  • Use real-time for automatic updates

  • Aggregate earnings in application layer

Future Enhancements

Potential Features

  • Bonus Multipliers: Limited-time cashback boosts

  • VIP Tiers: Exclusive invite-only tiers

  • Cashback Tokens: Earn native platform tokens

  • Leaderboards: Top earners by tier

  • Referral Bonuses: Extra cashback for referrals

  • Auto-Claim: Automatic claiming at threshold

Technical Improvements

  • Database function for atomic cashback recording

  • Scheduled job for batch tier upgrades

  • Analytics dashboard for cashback trends

  • A/B testing framework for multipliers

Last updated

Was this helpful?