Skip to content

Commit

Permalink
Merge pull request #68 from ikemHood/referral-contract
Browse files Browse the repository at this point in the history
Referral contract
  • Loading branch information
aguilar1x authored Feb 27, 2025
2 parents dcd8ebc + b24d98d commit 35befb1
Show file tree
Hide file tree
Showing 21 changed files with 14,630 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"StarShopContracts/implement-payment-contract",
"StarShopContracts/product-follow-contract",
"StarShopContracts/product-voting-contract",
"StarShopContracts/referral-contract",
]

[workspace.dependencies]
Expand All @@ -24,4 +25,4 @@ lto = true
# For more information about this profile see https://soroban.stellar.org/docs/basic-tutorials/logging#cargotoml-profile
[profile.release-with-logs]
inherits = "release"
debug-assertions = true
debug-assertions = true
15 changes: 15 additions & 0 deletions StarShopContracts/referral-contract/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "referral-contract"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { workspace = true }

[dev-dependencies]
soroban-sdk = { workspace = true, features = ["testutils"] }
145 changes: 145 additions & 0 deletions StarShopContracts/referral-contract/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Multi-Level Referral Smart Contract

A Soroban smart contract implementing a sophisticated multi-level referral
system with reward tracking, commission distribution, and user verification.

## 🌟 Features

### Referral System

- Multi-level referral tracking (up to 3 levels)
- Automatic commission distribution
- Team size tracking across levels
- Verified referrer requirements

### User Levels

- 4-tier system: Basic β†’ Silver β†’ Gold β†’ Platinum
- Automatic level progression
- Configurable requirements per level:
- Direct referrals count
- Team size
- Total rewards earned

### Reward Structure

- Tiered commission rates:
- Level 1: 5% (configurable)
- Level 2: 2% (configurable)
- Level 3: 1% (configurable)
- Milestone-based rewards
- Reward caps per referral
- Automatic distribution

### Verification System

- KYC verification requirement
- Admin approval process
- Verification status tracking
- Identity proof storage

### Security Features

- Contract pause mechanism
- Admin controls
- Authorization checks
- Duplicate prevention
- Activity tracking

## πŸ“‹ Prerequisites

- Rust toolchain
- Soroban CLI

## πŸ›  Setup

1. Install dependencies:

```bash
make build
```

## πŸ“ Contract Interface

### Admin Operations

```rust
fn initialize(env: Env, admin: Address, reward_token: Address) -> Result<(), Error>
fn set_reward_rates(env: Env, rates: RewardRates) -> Result<(), Error>
fn set_level_requirements(env: Env, requirements: LevelRequirements) -> Result<(), Error>
fn pause_contract(env: Env) -> Result<(), Error>
fn resume_contract(env: Env) -> Result<(), Error>
```

### User Operations

```rust
fn register_with_referral(env: Env, user: Address, referrer: Address, identity_proof: String) -> Result<(), Error>
fn submit_verification(env: Env, user: Address, identity_proof: String) -> Result<(), Error>
fn claim_rewards(env: Env, user: Address) -> Result<i128, Error>
```

### Query Operations

```rust
fn get_user_info(env: Env, user: Address) -> Result<UserData, Error>
fn get_pending_rewards(env: Env, user: Address) -> Result<i128, Error>
fn get_verification_status(env: Env, user: Address) -> Result<VerificationStatus, Error>
```

## πŸ— Contract Structure

```text
referral-contract/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ lib.rs # Contract entry points
β”‚ β”œβ”€β”€ admin.rs # Admin operations
β”‚ β”œβ”€β”€ referral.rs # Referral logic
β”‚ β”œβ”€β”€ rewards.rs # Reward management
β”‚ β”œβ”€β”€ verification.rs # User verification
β”‚ β”œβ”€β”€ level.rs # Level management
β”‚ β”œβ”€β”€ types.rs # Data structures
β”‚ β”œβ”€β”€ helpers.rs # Utility functions
β”‚ └── test.rs # Test suite
└── Cargo.toml
```

## πŸ”„ User Flow

1. User Registration
- Register with referrer
- Submit verification documents
- Await verification approval

2. Level Progression
- Meet level requirements
- Automatic level upgrades
- Access level benefits

3. Reward Distribution
- Earn commissions from referrals
- Achieve milestones
- Claim rewards

## πŸ” Security Considerations

- All critical operations require verification
- Admin operations are protected
- Reward caps prevent abuse
- Pause mechanism for emergencies

## πŸ“Š Metrics & Analytics

- Total users tracking
- Reward distribution stats
- Referral conversion rates
- Level distribution
- System performance metrics

## πŸ§ͺ Testing

Run the test suite:

```bash
make test
```
Loading

0 comments on commit 35befb1

Please sign in to comment.