Skip to content
Merged
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
49 changes: 31 additions & 18 deletions contracts/predictify-hybrid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,13 @@ impl PredictifyHybrid {
// Emit winnings claimed event
EventEmitter::emit_winnings_claimed(&env, &market_id, &user, payout);

// Transfer tokens
match bets::BetUtils::unlock_funds(&env, &user, payout) {
// Credit tokens to user balance
match storage::BalanceStorage::add_balance(
&env,
&user,
&types::ReflectorAsset::Stellar,
payout,
) {
Ok(_) => {}
Err(e) => panic_with_error!(env, e),
}
Expand Down Expand Up @@ -1841,6 +1846,11 @@ impl PredictifyHybrid {

// Sum bet amounts
for user in bettors.iter() {
// Avoid double counting if user is already in votes (legacy support)
if market.votes.contains_key(user.clone()) {
continue;
}

if let Some(bet) = bets::BetStorage::get_bet(&env, &market_id, &user) {
if bet.outcome == *winning_outcome {
winning_total += bet.amount;
Expand Down Expand Up @@ -1884,6 +1894,15 @@ impl PredictifyHybrid {
total_distributed = total_distributed
.checked_add(payout)
.ok_or(Error::InvalidInput)?;

// Credit winnings to user balance
storage::BalanceStorage::add_balance(
&env,
&user,
&types::ReflectorAsset::Stellar,
payout,
)?;

EventEmitter::emit_winnings_claimed(&env, &market_id, &user, payout);
}
}
Expand Down Expand Up @@ -1915,11 +1934,17 @@ impl PredictifyHybrid {
bet.status = BetStatus::Won;
let _ = bets::BetStorage::store_bet(&env, &bet);

EventEmitter::emit_winnings_claimed(&env, &market_id, &user, payout);
match bets::BetUtils::unlock_funds(&env, &user, payout) {
// Credit winnings to user balance instead of direct transfer
match storage::BalanceStorage::add_balance(
&env,
&user,
&types::ReflectorAsset::Stellar,
payout,
) {
Ok(_) => {}
Err(e) => panic_with_error!(env, e),
}
EventEmitter::emit_winnings_claimed(&env, &market_id, &user, payout);
}
}
} else {
Expand Down Expand Up @@ -2718,13 +2743,7 @@ impl PredictifyHybrid {
env.storage().persistent().set(&market_id, &market);

// Emit category update event
EventEmitter::emit_category_updated(
&env,
&market_id,
&old_category,
&category,
&admin,
);
EventEmitter::emit_category_updated(&env, &market_id, &old_category, &category, &admin);

Ok(())
}
Expand Down Expand Up @@ -2843,13 +2862,7 @@ impl PredictifyHybrid {
env.storage().persistent().set(&market_id, &market);

// Emit tags update event
EventEmitter::emit_tags_updated(
&env,
&market_id,
&old_tags,
&tags,
&admin,
);
EventEmitter::emit_tags_updated(&env, &market_id, &old_tags, &tags, &admin);

Ok(())
}
Expand Down
Loading