diff --git a/tokens/src/lib.rs b/tokens/src/lib.rs index a7ddbfb5b..861b4c3cd 100644 --- a/tokens/src/lib.rs +++ b/tokens/src/lib.rs @@ -474,8 +474,16 @@ impl MultiCurrencyExtended for Module { return Ok(()); } + // Ensure this doesn't overflow. There isn't any traits that exposes + // `saturating_abs` so we need to do it manually. + let by_amount_abs = if by_amount == Self::Amount::min_value() { + Self::Amount::max_value() + } else { + by_amount.abs() + }; + let by_balance = - TryInto::::try_into(by_amount.abs()).map_err(|_| Error::::AmountIntoBalanceFailed)?; + TryInto::::try_into(by_amount_abs).map_err(|_| Error::::AmountIntoBalanceFailed)?; if by_amount.is_positive() { Self::deposit(currency_id, who, by_balance) } else {