@@ -1425,7 +1425,7 @@ impl<T: Config> Pallet<T> {
1425
1425
Self :: update_reward_supply_index ( asset_id) ?;
1426
1426
Self :: distribute_supplier_reward ( asset_id, who) ?;
1427
1427
1428
- let exchange_rate = Self :: exchange_rate_stored ( asset_id) ?;
1428
+ let exchange_rate: FixedU128 = Self :: exchange_rate_stored ( asset_id) ?;
1429
1429
let redeem_amount = Self :: calc_underlying_amount ( voucher_amount, exchange_rate) ?;
1430
1430
1431
1431
AccountDeposits :: < T > :: try_mutate_exists ( asset_id, who, |deposits| -> DispatchResult {
@@ -1538,11 +1538,16 @@ impl<T: Config> Pallet<T> {
1538
1538
) -> DispatchResult {
1539
1539
let deposits = AccountDeposits :: < T > :: get ( asset_id, who) ;
1540
1540
let account_earned = AccountEarned :: < T > :: get ( asset_id, who) ;
1541
- let total_earned_prior_new = exchange_rate
1542
- . checked_sub ( & account_earned. exchange_rate_prior )
1543
- . and_then ( |r| r. checked_mul_int ( deposits. voucher_balance ) )
1544
- . and_then ( |r| r. checked_add ( account_earned. total_earned_prior ) )
1545
- . ok_or ( ArithmeticError :: Overflow ) ?;
1541
+
1542
+ let total_earned_prior_new = if exchange_rate >= account_earned. exchange_rate_prior {
1543
+ exchange_rate
1544
+ . checked_sub ( & account_earned. exchange_rate_prior )
1545
+ . and_then ( |delta| delta. checked_mul_int ( deposits. voucher_balance ) )
1546
+ . and_then ( |result| result. checked_add ( account_earned. total_earned_prior ) )
1547
+ . ok_or ( ArithmeticError :: Overflow ) ?
1548
+ } else {
1549
+ account_earned. total_earned_prior
1550
+ } ;
1546
1551
1547
1552
AccountEarned :: < T > :: insert (
1548
1553
asset_id,
0 commit comments