fn try_withdraw(
			pool_info: &mut PoolInfo<T::AccountId, BalanceOf<T>>,
			user_info: &mut UserStakeInfo<T::AccountId, BalanceOf<T>>,
			shares: BalanceOf<T>,
		) {
			pool_info.settle_user_pending_reward(user_info);
			let free_shares = match pool_info.share_price() {
				Some(price) if price != fp!(0) => bdiv(pool_info.free_stake, &price),
				// LOL, 100% slashed. We allow to withdraw all any number of shares with zero token
				// in return.
				_ => shares,
			};
			// The user is requesting to withdraw `shares`. So we compare the maximal free shares
			// with that of the request. The `shares` in the request is splitted to:
			// - `withdraw_shares`: can be withdrawn immedately
			// - `queued_shares`: enqueued in the withdrawl queue
			// We remove the dust in both values.
			let withdrawing_shares = shares.min(free_shares);
			let (withdrawing_shares, _) = extract_dust(withdrawing_shares);
			let queued_shares = shares - withdrawing_shares;
			let (queued_shares, _) = extract_dust(queued_shares);
			// Try withdraw immediately if we can
			if withdrawing_shares > Zero::zero() {
				Self::maybe_settle_slash(pool_info, user_info);
				// Overflow warning: remove_stake is carefully written to avoid precision error.
				// (I hope so)
				let (reduced, dust) = pool_info
					.remove_stake(user_info, withdrawing_shares)
					.expect("There are enough withdrawing_shares; qed.");
				Self::ledger_reduce(&user_info.user, reduced, dust);
				Self::deposit_event(Event::<T>::Withdrawal(
					pool_info.pid,
					user_info.user.clone(),
					reduced,
				));
			}
			// Some locked assets haven't been withdrawn (unlocked) to user, add it to the withdraw
			// queue. When the pool has free stake again, the withdrawal will be fulfilled.
			if queued_shares > Zero::zero() {
				let now = <T as registry::Config>::UnixTime::now()
					.as_secs()
					.saturated_into::<u64>();
				pool_info.withdraw_queue.push_back(WithdrawInfo {
					user: user_info.user.clone(),
					shares: queued_shares,
					start_time: now,
				});
				Self::maybe_add_withdraw_queue(now, pool_info.pid);
			}
			// Update the pending reward after changing the staked amount
			pool_info.reset_pending_reward(user_info);
		}
/// Tries to withdraw a specific amount from a pool.
///
/// The withdraw request would be delayed if the free stake is not enough, otherwise
/// withdraw from the free stake immediately.
///
/// The updates are made in `pool_info` and `user_info`. It's up to the caller to persist
/// the data.
///
/// Requires:
/// 1. The user's pending slash is already settled.
/// 2. The pool must has shares and stake (or it can cause division by zero error)
Tries to withdraw a specific amount from a pool.
The withdraw request would be delayed if the free stake is not enough, otherwise
withdraw from the free stake immediately.

The updates are made in `pool_info` and `user_info`. It's up to the caller to persist
the data.

1. The user's pending slash is already settled.
2. The pool must has shares and stake (or it can cause division by zero error)
Tries to withdraw a specific amount from a pool . The withdraw request would be delayed if the free stake is not enough otherwise withdraw from the free stake immediately . The updates are made in ` pool_info ` and ` user_info ` . It ' s up to the caller to persist the data . 1 . The user ' s pending slash is already settled . 2 . The pool must has shares and stake ( or it can cause division by zero error )
fn try_withdraw(
			pool_info: &mut PoolInfo<T::AccountId, BalanceOf<T>>,
			user_info: &mut UserStakeInfo<T::AccountId, BalanceOf<T>>,
			shares: BalanceOf<T>,
		) {
			pool_info.settle_user_pending_reward(user_info);
			let free_shares = match pool_info.share_price() {
				Some(price) if price != fp!(0) => bdiv(pool_info.free_stake, &price),
				// LOL, 100% slashed. We allow to withdraw all any number of shares with zero token
				// in return.
				_ => shares,
			};
			// The user is requesting to withdraw `shares`. So we compare the maximal free shares
			// with that of the request. The `shares` in the request is splitted to:
			// - `withdraw_shares`: can be withdrawn immedately
			// - `queued_shares`: enqueued in the withdrawl queue
			// We remove the dust in both values.
			let withdrawing_shares = shares.min(free_shares);
			let (withdrawing_shares, _) = extract_dust(withdrawing_shares);
			let queued_shares = shares - withdrawing_shares;
			let (queued_shares, _) = extract_dust(queued_shares);
			// Try withdraw immediately if we can
			if withdrawing_shares > Zero::zero() {
				Self::maybe_settle_slash(pool_info, user_info);
				// Overflow warning: remove_stake is carefully written to avoid precision error.
				// (I hope so)
				let (reduced, dust) = pool_info
					.remove_stake(user_info, withdrawing_shares)
					.expect("There are enough withdrawing_shares; qed.");
				Self::ledger_reduce(&user_info.user, reduced, dust);
				Self::deposit_event(Event::<T>::Withdrawal(
					pool_info.pid,
					user_info.user.clone(),
					reduced,
				));
			}
			// Some locked assets haven't been withdrawn (unlocked) to user, add it to the withdraw
			// queue. When the pool has free stake again, the withdrawal will be fulfilled.
			if queued_shares > Zero::zero() {
				let now = <T as registry::Config>::UnixTime::now()
					.as_secs()
					.saturated_into::<u64>();
				pool_info.withdraw_queue.push_back(WithdrawInfo {
					user: user_info.user.clone(),
					shares: queued_shares,
					start_time: now,
				});
				Self::maybe_add_withdraw_queue(now, pool_info.pid);
			}
			// Update the pending reward after changing the staked amount
			pool_info.reset_pending_reward(user_info);
		}
fn try_withdraw ( pool_info : & mut PoolInfo < T :: AccountId , BalanceOf < T > > , user_info : & mut UserStakeInfo < T :: AccountId , BalanceOf < T > > , shares : BalanceOf < T > , ) { pool_info . settle_user_pending_reward ( user_info ) ; let free_shares = match pool_info . share_price ( ) { Some ( price ) if price != fp ! ( 0 ) => bdiv ( pool_info . free_stake , & price ) , // LOL, 100% slashed. We allow to withdraw all any number of shares with zero token // in return. _ => shares , } ; // The user is requesting to withdraw `shares`. So we compare the maximal free shares // with that of the request. The `shares` in the request is splitted to: // - `withdraw_shares`: can be withdrawn immedately // - `queued_shares`: enqueued in the withdrawl queue // We remove the dust in both values. let withdrawing_shares = shares . min ( free_shares ) ; let ( withdrawing_shares , _ ) = extract_dust ( withdrawing_shares ) ; let queued_shares = shares - withdrawing_shares ; let ( queued_shares , _ ) = extract_dust ( queued_shares ) ; // Try withdraw immediately if we can if withdrawing_shares > Zero :: zero ( ) { Self :: maybe_settle_slash ( pool_info , user_info ) ; // Overflow warning: remove_stake is carefully written to avoid precision error. // (I hope so) let ( reduced , dust ) = pool_info . remove_stake ( user_info , withdrawing_shares ) . expect ( " " ) ; Self :: ledger_reduce ( & user_info . user , reduced , dust ) ; Self :: deposit_event ( Event :: < T > :: Withdrawal ( pool_info . pid , user_info . user . clone ( ) , reduced , ) ) ; } // Some locked assets haven't been withdrawn (unlocked) to user, add it to the withdraw // queue. When the pool has free stake again, the withdrawal will be fulfilled. if queued_shares > Zero :: zero ( ) { let now = < T as registry :: Config > :: UnixTime :: now ( ) . as_secs ( ) . saturated_into :: < u64 > ( ) ; pool_info . withdraw_queue . push_back ( WithdrawInfo { user : user_info . user . clone ( ) , shares : queued_shares , start_time : now , } ) ; Self :: maybe_add_withdraw_queue ( now , pool_info . pid ) ; } // Update the pending reward after changing the staked amount pool_info . reset_pending_reward ( user_info ) ; }
Tries to withdraw a specific amount from a pool.
Tries to withdraw a specific amount from a pool .
pool_info
&mut PoolInfo<T::AccountId, BalanceOf<T>>
user_info
&mut UserStakeInfo<T::AccountId, BalanceOf<T>>
shares
BalanceOf<T>
pool_info
&mut PoolInfo<T::AccountId, BalanceOf<T>>
user_info
&mut UserStakeInfo<T::AccountId, BalanceOf<T>>
shares
BalanceOf<T>