Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 fix withdraw_claim #659

Merged
merged 1 commit into from
Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pallets/farming/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -499,7 +499,7 @@ pub mod pallet {
let exchanger = ensure_signed(origin)?;

let pool_info = Self::pool_infos(&pid).ok_or(Error::<T>::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(())
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions pallets/farming/src/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ impl<T: Config> Pallet<T> {
who: &T::AccountId,
pool: PoolId,
pool_info: &PoolInfo<BalanceOf<T>, CurrencyIdOf<T>, AccountIdOf<T>, BlockNumberFor<T>>,
if_remove: bool,
) -> DispatchResult {
SharesAndWithdrawnRewards::<T>::mutate_exists(
pool,
Expand Down Expand Up @@ -417,10 +418,11 @@ impl<T: Config> Pallet<T> {
)?;
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<T>, BalanceOf<T>)>::default() ||
!share_info.share.is_zero()
!share_info.share.is_zero() ||
!if_remove
{
*share_info_old = Some(share_info);
};
Expand Down
2 changes: 1 addition & 1 deletion pallets/farming/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <Runtime as Config>::MultiCurrency::minimum_balance(KSM);
Expand Down