Skip to content

Commit

Permalink
fix: use safe math to add amounts in add_coin_to_basket function
Browse files Browse the repository at this point in the history
  • Loading branch information
nseguias committed Sep 24, 2024
1 parent b49fa36 commit d26e3d8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions contracts/injective-auction-pool/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) fn new_auction_round(
denom: coin.denom.clone(),
amount: net_amount,
},
)
)?
}
}

Expand Down Expand Up @@ -306,12 +306,13 @@ pub(crate) fn query_current_auction(
}

// Adds coins to the basket or increments the amount if the coin already exists (avoiding duplicates)
fn add_coin_to_basket(basket: &mut Vec<Coin>, coin: Coin) {
fn add_coin_to_basket(basket: &mut Vec<Coin>, coin: Coin) -> Result<(), ContractError> {
if let Some(existing_coin) = basket.iter_mut().find(|c| c.denom == coin.denom) {
existing_coin.amount += coin.amount;
existing_coin.amount = existing_coin.amount.checked_add(coin.amount)?;
} else {
basket.push(coin);
}
Ok(())
}

/// Queries the latest auction result
Expand Down

0 comments on commit d26e3d8

Please sign in to comment.