Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion contracts/hunty-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,15 +607,37 @@ impl HuntyCore {
if let Some(reward_manager_addr) = Storage::get_reward_manager(&env) {
let mut balance_args: Vec<Val> = Vec::new(&env);
balance_args.push_back(hunt_id.into_val(&env));

// Query the pool balance from the reward manager
let pool_balance = match env.try_invoke_contract::<i128, RewardErrorCode>(
&reward_manager_addr,
&Symbol::new(&env, "get_pool_balance"),
balance_args,
balance_args.clone(),
) {
Ok(Ok(balance)) => balance,
_ => return Err(HuntErrorCode::InsufficientRewardPool),
};
hunt.reward_config.xlm_pool = pool_balance;

// Query the minimum distribution amount for this pool
let min_distribution_amount = match env.try_invoke_contract::<i128, RewardErrorCode>(
&reward_manager_addr,
&Symbol::new(&env, "get_min_distribution_amount"),
balance_args,
) {
Ok(Ok(amount)) => amount,
_ => 0,
};

// Validate pool balance >= min_distribution_amount * max_winners
if min_distribution_amount > 0 && hunt.reward_config.max_winners > 0 {
let required =
min_distribution_amount.saturating_mul(hunt.reward_config.max_winners as i128);
if pool_balance < required {
return Err(HuntErrorCode::InsufficientRewardPool);
}
}

if !hunt.has_rewards_available() {
return Err(HuntErrorCode::InsufficientRewardPool);
}
Expand Down
8 changes: 8 additions & 0 deletions contracts/reward-manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
DistributionRecord, DistributionStatus, RewardConfig, RewardPoolConfig, RewardPoolStatus,
SemVer, ValidationResult,
};
use crate::xlm_handler::XlmHandler;

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

unresolved import `crate::types::ResolutionStatus`

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `RewardPoolConfig` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `DistributionStatus` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `DistributionRecord` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `RewardConfig` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

unresolved import `crate::types::ResolutionStatus`

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `RewardPoolConfig` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `DistributionStatus` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `DistributionRecord` is defined multiple times

Check failure on line 13 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `RewardConfig` is defined multiple times

Check failure on line 14 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `ValidationResult` is defined multiple times

Check failure on line 14 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `SemVer` is defined multiple times

Check failure on line 14 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

the name `RewardPoolStatus` is defined multiple times

Check failure on line 14 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `ValidationResult` is defined multiple times

Check failure on line 14 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `SemVer` is defined multiple times

Check failure on line 14 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

the name `RewardPoolStatus` is defined multiple times
// Funding validation constants
// 1 XLM = 10_000_000 stroops (Stellar's base unit)
/// Minimum funding amount: 1 XLM (prevents dust attacks)
Expand Down Expand Up @@ -436,7 +436,7 @@
let balance = Storage::get_pool_balance(&env, hunt_id);
let total_deposited = Storage::get_pool_total_deposited(&env, hunt_id);
let total_distributed = Storage::get_pool_total_distributed(&env, hunt_id);

Check failure on line 439 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Test

symbol too long: length 10, max 9

Check failure on line 439 in contracts/reward-manager/src/lib.rs

View workflow job for this annotation

GitHub Actions / Clippy

symbol too long: length 10, max 9
Some(RewardPoolStatus {
balance,
total_deposited,
Expand Down Expand Up @@ -699,6 +699,14 @@
Storage::get_pool_balance(&env, hunt_id)
}

/// Returns the minimum distribution amount configured for a hunt's reward pool.
/// Returns 0 if no pool has been created for the hunt.
pub fn get_min_distribution_amount(env: Env, hunt_id: u64) -> i128 {
Storage::get_pool_config(&env, hunt_id)
.map(|config| config.min_distribution_amount)
.unwrap_or(0)
}

/// Returns whether a reward has been distributed to a player for a hunt.
pub fn is_reward_distributed(env: Env, hunt_id: u64, player: Address) -> bool {
Storage::is_distributed(&env, hunt_id, &player)
Expand Down
Loading