-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from ikemHood/referral-contract
Referral contract
- Loading branch information
Showing
21 changed files
with
14,630 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
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"] } |
This file contains 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
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 | ||
``` |
Oops, something went wrong.