Skip to content

Commit

Permalink
Correct div by 0 I introduced
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Dec 5, 2023
1 parent 8cc0adf commit 095ac50
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions substrate/dex/pallet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,10 @@ pub mod pallet {
for coin in Pools::<T>::iter_keys() {
// insert the new price to our oracle window
// The spot price for 1 coin, in atomic units, to SRI is used
let pool_id = Self::get_pool_id(coin, Coin::native()).ok().unwrap();
let pool_account = Self::get_pool_account(pool_id);
let sri_balance = Self::get_balance(&pool_account, Coin::native());
let coin_balance = Self::get_balance(&pool_account, coin);
let Ok((sri_balance, coin_balance)) = Self::get_reserves(&Coin::native(), &coin) else {
continue;
};

// We use 1 coin to handle rounding errors which may occur with atomic units
// If we used atomic units, any coin whose atomic unit is worth less than SRI's atomic unit
// would cause a 'price' of 0
Expand Down Expand Up @@ -754,7 +754,7 @@ pub mod pallet {
/// Swap coins along a `path`, depositing in `send_to`.
pub(crate) fn do_swap(
sender: T::AccountId,
amounts: &Vec<SubstrateAmount>,
amounts: &[SubstrateAmount],
path: BoundedVec<Coin, T::MaxSwapPathLength>,
send_to: T::AccountId,
) -> Result<(), DispatchError> {
Expand Down

0 comments on commit 095ac50

Please sign in to comment.