pub fn liquidate_unsafe_loan(borrower: T::AccountId, liquidated_pool_id: CurrencyId) -> DispatchResult {
		<T as module::Config>::ControllerManager::accrue_interest_rate(liquidated_pool_id)?;

		// Read prices price for borrowed pool.
		let price_borrowed =
			T::PriceSource::get_underlying_price(liquidated_pool_id).ok_or(Error::<T>::InvalidFeedPrice)?;

		// Get borrower borrow balance and calculate total_repay_amount (in USD):
		// total_repay_amount = borrow_balance * price_borrowed
		let borrow_balance =
			<T as module::Config>::ControllerManager::borrow_balance_stored(&borrower, liquidated_pool_id)?;
		let total_repay_amount = Rate::from_inner(borrow_balance)
			.checked_mul(&price_borrowed)
			.map(|x| x.into_inner())
			.ok_or(Error::<T>::NumOverflow)?;

		let liquidation_attempts = <LiquidityPools<T>>::get_user_liquidation_attempts(&borrower, liquidated_pool_id);

		let is_partial_liquidation = total_repay_amount
			>= RiskManagerParams::<T>::get(liquidated_pool_id).min_partial_liquidation_sum
			&& liquidation_attempts < RiskManagerParams::<T>::get(liquidated_pool_id).max_attempts;

		// Calculate sum required to liquidate.
		let (seize_amount, is_attempt_increment_required) =
			Self::calculate_liquidation_info(liquidated_pool_id, total_repay_amount, is_partial_liquidation)?;

		let (seized_pools, repay_amount) = Self::liquidate_borrow_fresh(&borrower, liquidated_pool_id, seize_amount)?;

		if is_attempt_increment_required {
			Self::mutate_liquidation_attempts(liquidated_pool_id, &borrower, is_partial_liquidation);
		}

		Self::deposit_event(Event::LiquidateUnsafeLoan(
			borrower,
			repay_amount,
			liquidated_pool_id,
			seized_pools,
			is_partial_liquidation,
		));

		Ok(())
	}
/// Defines the type of liquidation (partial or full) and causes liquidation.
///
/// - `borrower`: the borrower in automatic liquidation.
/// - `liquidated_pool_id`: the CurrencyId of the pool with loan, for which automatic
/// liquidation is performed.
Defines the type of liquidation (partial or full) and causes liquidation.
`borrower`: the borrower in automatic liquidation.
`liquidated_pool_id`: the CurrencyId of the pool with loan, for which automatic
liquidation is performed.
Defines the type of liquidation ( partial or full ) and causes liquidation . ` borrower ` : the borrower in automatic liquidation . ` liquidated_pool_id ` : the CurrencyId of the pool with loan for which automatic liquidation is performed .
pub fn liquidate_unsafe_loan(borrower: T::AccountId, liquidated_pool_id: CurrencyId) -> DispatchResult {
		<T as module::Config>::ControllerManager::accrue_interest_rate(liquidated_pool_id)?;
		// Read prices price for borrowed pool.
		let price_borrowed =
			T::PriceSource::get_underlying_price(liquidated_pool_id).ok_or(Error::<T>::InvalidFeedPrice)?;
		// Get borrower borrow balance and calculate total_repay_amount (in USD):
		// total_repay_amount = borrow_balance * price_borrowed
		let borrow_balance =
			<T as module::Config>::ControllerManager::borrow_balance_stored(&borrower, liquidated_pool_id)?;
		let total_repay_amount = Rate::from_inner(borrow_balance)
			.checked_mul(&price_borrowed)
			.map(|x| x.into_inner())
			.ok_or(Error::<T>::NumOverflow)?;
		let liquidation_attempts = <LiquidityPools<T>>::get_user_liquidation_attempts(&borrower, liquidated_pool_id);
		let is_partial_liquidation = total_repay_amount
			>= RiskManagerParams::<T>::get(liquidated_pool_id).min_partial_liquidation_sum
			&& liquidation_attempts < RiskManagerParams::<T>::get(liquidated_pool_id).max_attempts;
		// Calculate sum required to liquidate.
		let (seize_amount, is_attempt_increment_required) =
			Self::calculate_liquidation_info(liquidated_pool_id, total_repay_amount, is_partial_liquidation)?;
		let (seized_pools, repay_amount) = Self::liquidate_borrow_fresh(&borrower, liquidated_pool_id, seize_amount)?;
		if is_attempt_increment_required {
			Self::mutate_liquidation_attempts(liquidated_pool_id, &borrower, is_partial_liquidation);
		}
		Self::deposit_event(Event::LiquidateUnsafeLoan(
			borrower,
			repay_amount,
			liquidated_pool_id,
			seized_pools,
			is_partial_liquidation,
		));
		Ok(())
	}
pub fn liquidate_unsafe_loan ( borrower : T :: AccountId , liquidated_pool_id : CurrencyId ) -> DispatchResult { < T as module :: Config > :: ControllerManager :: accrue_interest_rate ( liquidated_pool_id ) ? ; // Read prices price for borrowed pool. let price_borrowed = T :: PriceSource :: get_underlying_price ( liquidated_pool_id ) . ok_or ( Error :: < T > :: InvalidFeedPrice ) ? ; // Get borrower borrow balance and calculate total_repay_amount (in USD): // total_repay_amount = borrow_balance * price_borrowed let borrow_balance = < T as module :: Config > :: ControllerManager :: borrow_balance_stored ( & borrower , liquidated_pool_id ) ? ; let total_repay_amount = Rate :: from_inner ( borrow_balance ) . checked_mul ( & price_borrowed ) . map ( | x | x . into_inner ( ) ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let liquidation_attempts = < LiquidityPools < T > > :: get_user_liquidation_attempts ( & borrower , liquidated_pool_id ) ; let is_partial_liquidation = total_repay_amount >= RiskManagerParams :: < T > :: get ( liquidated_pool_id ) . min_partial_liquidation_sum && liquidation_attempts < RiskManagerParams :: < T > :: get ( liquidated_pool_id ) . max_attempts ; // Calculate sum required to liquidate. let ( seize_amount , is_attempt_increment_required ) = Self :: calculate_liquidation_info ( liquidated_pool_id , total_repay_amount , is_partial_liquidation ) ? ; let ( seized_pools , repay_amount ) = Self :: liquidate_borrow_fresh ( & borrower , liquidated_pool_id , seize_amount ) ? ; if is_attempt_increment_required { Self :: mutate_liquidation_attempts ( liquidated_pool_id , & borrower , is_partial_liquidation ) ; } Self :: deposit_event ( Event :: LiquidateUnsafeLoan ( borrower , repay_amount , liquidated_pool_id , seized_pools , is_partial_liquidation , ) ) ; Ok ( ( ) ) }
Defines the type of liquidation (partial or full) and causes liquidation.
Defines the type of liquidation ( partial or full ) and causes liquidation .
borrower
T::AccountId
liquidated_pool_id
CurrencyId
borrower
T::AccountId
liquidated_pool_id
CurrencyId