pub fn calculate_current_pool_data(pool_id: CurrencyId) -> result::Result<Pool, DispatchError> {
		let current_block_number = <frame_system::Pallet<T>>::block_number();
		let accrual_block_number_previous = Self::controller_dates(pool_id).last_interest_accrued_block;
		if current_block_number == accrual_block_number_previous {
			return Ok(<LiquidityPools<T>>::get_pool_data(pool_id));
		}

		let block_delta = Self::calculate_block_delta(current_block_number, accrual_block_number_previous)?;
		let current_total_balance = T::LiquidityPoolsManager::get_pool_available_liquidity(pool_id);
		let pool_data = <LiquidityPools<T>>::get_pool_data(pool_id);

		let utilization_rate = Self::calculate_utilization_rate(
			current_total_balance,
			pool_data.total_borrowed,
			pool_data.total_protocol_interest,
		)?;

		// Calculate the current borrow interest rate
		let current_borrow_interest_rate =
			T::MinterestModelManager::calculate_borrow_interest_rate(pool_id, utilization_rate)?;

		let ControllerData {
			max_borrow_rate,
			protocol_interest_factor,
			..
		} = Self::controller_dates(pool_id);

		ensure!(
			current_borrow_interest_rate <= max_borrow_rate,
			Error::<T>::BorrowRateTooHigh
		);

		/*
		Calculate the interest accumulated into borrows and protocol interest and the new index:
			*  simpleInterestFactor = borrowRate * blockDelta
			*  interestAccumulated = simpleInterestFactor * totalBorrows
			*  totalBorrowsNew = interestAccumulated + totalBorrows
			*  totalProtocolInterestNew = interestAccumulated * protocolInterestFactor + totalProtocolInterest
			*  borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
		*/

		let simple_interest_factor = Self::calculate_interest_factor(current_borrow_interest_rate, block_delta)?;

		let interest_accumulated = Rate::from_inner(pool_data.total_borrowed)
			.checked_mul(&simple_interest_factor)
			.map(|x| x.into_inner())
			.ok_or(Error::<T>::BalanceOverflow)?;

		let total_borrowed = interest_accumulated
			.checked_add(pool_data.total_borrowed)
			.ok_or(Error::<T>::BorrowBalanceOverflow)?;

		let total_protocol_interest = sum_with_mult_result(
			pool_data.total_protocol_interest,
			interest_accumulated,
			protocol_interest_factor,
		)
		.map_err(|_| Error::<T>::ProtocolInterestOverflow)?;

		let borrow_index = simple_interest_factor
			.checked_mul(&pool_data.borrow_index)
			.and_then(|v| v.checked_add(&pool_data.borrow_index))
			.ok_or(Error::<T>::NumOverflow)?;

		Ok(Pool {
			total_borrowed,
			borrow_index,
			total_protocol_interest,
		})
	}
/// Calculates pool borrows, pool protocol interest and pool borrow index for given pool.
/// Applies accrued interest to pool borrows and protocol interest and calculates interest
/// accrued from the last checkpointed block up to the current block.
///
/// - `pool_id`: CurrencyId to calculate parameters for.
///
/// Returns pool parameters calculated for a current block.




Returns pool parameters calculated for a current block.
Returns pool parameters calculated for a current block .
pub fn calculate_current_pool_data(pool_id: CurrencyId) -> result::Result<Pool, DispatchError> {
		let current_block_number = <frame_system::Pallet<T>>::block_number();
		let accrual_block_number_previous = Self::controller_dates(pool_id).last_interest_accrued_block;
		if current_block_number == accrual_block_number_previous {
			return Ok(<LiquidityPools<T>>::get_pool_data(pool_id));
		}
		let block_delta = Self::calculate_block_delta(current_block_number, accrual_block_number_previous)?;
		let current_total_balance = T::LiquidityPoolsManager::get_pool_available_liquidity(pool_id);
		let pool_data = <LiquidityPools<T>>::get_pool_data(pool_id);
		let utilization_rate = Self::calculate_utilization_rate(
			current_total_balance,
			pool_data.total_borrowed,
			pool_data.total_protocol_interest,
		)?;
		// Calculate the current borrow interest rate
		let current_borrow_interest_rate =
			T::MinterestModelManager::calculate_borrow_interest_rate(pool_id, utilization_rate)?;
		let ControllerData {
			max_borrow_rate,
			protocol_interest_factor,
			..
		} = Self::controller_dates(pool_id);
		ensure!(
			current_borrow_interest_rate <= max_borrow_rate,
			Error::<T>::BorrowRateTooHigh
		);
		/*
		Calculate the interest accumulated into borrows and protocol interest and the new index:
			*  simpleInterestFactor = borrowRate * blockDelta
			*  interestAccumulated = simpleInterestFactor * totalBorrows
			*  totalBorrowsNew = interestAccumulated + totalBorrows
			*  totalProtocolInterestNew = interestAccumulated * protocolInterestFactor + totalProtocolInterest
			*  borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
		*/
		let simple_interest_factor = Self::calculate_interest_factor(current_borrow_interest_rate, block_delta)?;
		let interest_accumulated = Rate::from_inner(pool_data.total_borrowed)
			.checked_mul(&simple_interest_factor)
			.map(|x| x.into_inner())
			.ok_or(Error::<T>::BalanceOverflow)?;
		let total_borrowed = interest_accumulated
			.checked_add(pool_data.total_borrowed)
			.ok_or(Error::<T>::BorrowBalanceOverflow)?;
		let total_protocol_interest = sum_with_mult_result(
			pool_data.total_protocol_interest,
			interest_accumulated,
			protocol_interest_factor,
		)
		.map_err(|_| Error::<T>::ProtocolInterestOverflow)?;
		let borrow_index = simple_interest_factor
			.checked_mul(&pool_data.borrow_index)
			.and_then(|v| v.checked_add(&pool_data.borrow_index))
			.ok_or(Error::<T>::NumOverflow)?;
		Ok(Pool {
			total_borrowed,
			borrow_index,
			total_protocol_interest,
		})
	}
pub fn calculate_current_pool_data ( pool_id : CurrencyId ) -> result :: Result < Pool , DispatchError > { let current_block_number = < frame_system :: Pallet < T > > :: block_number ( ) ; let accrual_block_number_previous = Self :: controller_dates ( pool_id ) . last_interest_accrued_block ; if current_block_number == accrual_block_number_previous { return Ok ( < LiquidityPools < T > > :: get_pool_data ( pool_id ) ) ; } let block_delta = Self :: calculate_block_delta ( current_block_number , accrual_block_number_previous ) ? ; let current_total_balance = T :: LiquidityPoolsManager :: get_pool_available_liquidity ( pool_id ) ; let pool_data = < LiquidityPools < T > > :: get_pool_data ( pool_id ) ; let utilization_rate = Self :: calculate_utilization_rate ( current_total_balance , pool_data . total_borrowed , pool_data . total_protocol_interest , ) ? ; // Calculate the current borrow interest rate let current_borrow_interest_rate = T :: MinterestModelManager :: calculate_borrow_interest_rate ( pool_id , utilization_rate ) ? ; let ControllerData { max_borrow_rate , protocol_interest_factor , .. } = Self :: controller_dates ( pool_id ) ; ensure ! ( current_borrow_interest_rate max_borrow_rate Error T BorrowRateTooHigh ) ; /*
		Calculate the interest accumulated into borrows and protocol interest and the new index:
			*  simpleInterestFactor = borrowRate * blockDelta
			*  interestAccumulated = simpleInterestFactor * totalBorrows
			*  totalBorrowsNew = interestAccumulated + totalBorrows
			*  totalProtocolInterestNew = interestAccumulated * protocolInterestFactor + totalProtocolInterest
			*  borrowIndexNew = simpleInterestFactor * borrowIndex + borrowIndex
		*/ let simple_interest_factor = Self :: calculate_interest_factor ( current_borrow_interest_rate , block_delta ) ? ; let interest_accumulated = Rate :: from_inner ( pool_data . total_borrowed ) . checked_mul ( & simple_interest_factor ) . map ( | x | x . into_inner ( ) ) . ok_or ( Error :: < T > :: BalanceOverflow ) ? ; let total_borrowed = interest_accumulated . checked_add ( pool_data . total_borrowed ) . ok_or ( Error :: < T > :: BorrowBalanceOverflow ) ? ; let total_protocol_interest = sum_with_mult_result ( pool_data . total_protocol_interest , interest_accumulated , protocol_interest_factor , ) . map_err ( | _ | Error :: < T > :: ProtocolInterestOverflow ) ? ; let borrow_index = simple_interest_factor . checked_mul ( & pool_data . borrow_index ) . and_then ( | v | v . checked_add ( & pool_data . borrow_index ) ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; Ok ( Pool { total_borrowed , borrow_index , total_protocol_interest , } ) }
Calculates pool borrows, pool protocol interest and pool borrow index for given pool.
Calculates pool borrows pool protocol interest and pool borrow index for given pool .
pool_id
CurrencyId
pool_id
CurrencyId