diff --git a/pallets/farming/src/lib.rs b/pallets/farming/src/lib.rs index 52ae81ca3..da50c825c 100644 --- a/pallets/farming/src/lib.rs +++ b/pallets/farming/src/lib.rs @@ -486,7 +486,7 @@ pub mod pallet { if let Some(ref gid) = pool_info.gauge { Self::gauge_claim_inner(&exchanger, *gid)?; } - Self::process_withraw_list(&exchanger, pid, &pool_info)?; + Self::process_withraw_list(&exchanger, pid, &pool_info, true)?; Self::deposit_event(Event::Claimed { who: exchanger, pid }); Ok(()) @@ -499,7 +499,7 @@ pub mod pallet { let exchanger = ensure_signed(origin)?; let pool_info = Self::pool_infos(&pid).ok_or(Error::::PoolDoesNotExist)?; - Self::process_withraw_list(&exchanger, pid, &pool_info)?; + Self::process_withraw_list(&exchanger, pid, &pool_info, false)?; Self::deposit_event(Event::WithdrawClaimed { who: exchanger, pid }); Ok(()) @@ -527,7 +527,7 @@ pub mod pallet { if let Some(ref gid) = pool_info.gauge { Self::gauge_claim_inner(&who, *gid)?; } - Self::process_withraw_list(&who, pid, &pool_info)?; + Self::process_withraw_list(&who, pid, &pool_info, true)?; } if all_retired { diff --git a/pallets/farming/src/rewards.rs b/pallets/farming/src/rewards.rs index 5d6548a73..3cd1b95ad 100644 --- a/pallets/farming/src/rewards.rs +++ b/pallets/farming/src/rewards.rs @@ -368,6 +368,7 @@ impl Pallet { who: &T::AccountId, pool: PoolId, pool_info: &PoolInfo, CurrencyIdOf, AccountIdOf, BlockNumberFor>, + if_remove: bool, ) -> DispatchResult { SharesAndWithdrawnRewards::::mutate_exists( pool, @@ -417,10 +418,11 @@ impl Pallet { )?; share_info.withdraw_list = tmp; - // if withdraw_list and share both are empty, remove it. + // if withdraw_list and share both are empty, and if_remove is true, remove it. if share_info.withdraw_list != Vec::<(BlockNumberFor, BalanceOf)>::default() || - !share_info.share.is_zero() + !share_info.share.is_zero() || + !if_remove { *share_info_old = Some(share_info); }; diff --git a/pallets/farming/src/tests.rs b/pallets/farming/src/tests.rs index 4cc76bd98..9315b1e9e 100644 --- a/pallets/farming/src/tests.rs +++ b/pallets/farming/src/tests.rs @@ -110,7 +110,7 @@ fn withdraw() { assert_eq!(Tokens::free_balance(KSM, &ALICE), 3966); assert_ok!(Farming::withdraw(Origin::signed(ALICE), pid, Some(200))); System::set_block_number(System::block_number() + 100); - assert_ok!(Farming::withdraw_claim(Origin::signed(ALICE), pid)); + assert_ok!(Farming::claim(Origin::signed(ALICE), pid)); assert_eq!(Farming::shares_and_withdrawn_rewards(pid, &ALICE), None); assert_eq!(Tokens::free_balance(KSM, &ALICE), 4166); let ed = ::MultiCurrency::minimum_balance(KSM);