Skip to content

[CT-09] Implement on-chain Referral Reward Split Calculator in Rust #1026

@devwums

Description

@devwums

Problem

Referral reward distribution has no standardised on-chain calculation. Reward splits are computed ad hoc on the backend, making them unauditable and gameable.

Proposed Solution

Create contracts/cntr/referral_reward.rs implementing pub fn calculate_referral_split(total_reward_stroops: i128, referrer_percent: u32) -> Result<(i128, i128), &'static str>. Returns (referrer_amount, referee_amount) where referrer_amount + referee_amount == total_reward_stroops always (any remainder from integer division goes to the referrer). All implementation must live inside contracts/cntr/.

Acceptance Criteria

  • File at contracts/cntr/referral_reward.rs
  • Returns Err("Referrer percent cannot exceed 100") for referrer_percent > 100
  • referrer_amount + referee_amount always equals total_reward_stroops exactly
  • Remainder from integer division is added to referrer_amount
  • At least 5 unit tests: 50/50, 100/0, 0/100, 70/30, odd total that produces a remainder
  • Compiles with cargo test

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions