Phoenix-Protocol-Group / phoenix-contracts

Source code of the smart contracts of the Phoenix DeFi hub DEX protocol
GNU General Public License v3.0
10 stars 6 forks source link

Pool: adds a validation and panic for when shares are equal to zero. #245

Closed gangov closed 7 months ago

gangov commented 7 months ago

if we do something like

let mut share_ratio = Decimal::zero();
let total_shares = utils::get_total_shares(&env);
if total_shares != 0i128 {
  share_ratio = Decimal::from_ratio(share_amount, total_shares);
} else {
  panic_with_err!(..)
}

then this makes the assignment of Decimal::zero(); to share_ratio conflict with the compiler.

Using two separate if statements seems too much for me, so that's why I go with this in the PR