fn update_mnt_borrow_index(underlying_id: CurrencyId) -> DispatchResult {
		// block_delta = current_block_number - borrow_state.index_updated_at_block
		// mnt_accrued = delta_blocks * mnt_speed
		// borrow_amount - mtoken.total_borrows() / liquidity_pool_borrow_index
		// ratio = mnt_accrued / borrow_amount
		// borrow_state.mnt_distribution_index(for current pool) += ratio
		// borrow_state.index_updated_at_block = current_block_number

		let mnt_speed = MntSpeeds::<T>::get(underlying_id);
		if mnt_speed.is_zero() {
			// Distribution is off
			return Ok(());
		}

		let current_block = frame_system::Pallet::<T>::block_number();
		let mut pool_state = MntPoolsState::<T>::get(underlying_id);
		let block_delta = current_block
			.checked_sub(&pool_state.borrow_state.index_updated_at_block)
			.ok_or(Error::<T>::NumOverflow)?;

		if block_delta.is_zero() {
			// Index for current block was already calculated
			return Ok(());
		}

		let block_delta_as_u128 = TryInto::<u128>::try_into(block_delta).or(Err(Error::<T>::InternalError))?;

		let mnt_accrued = mnt_speed
			.checked_mul(block_delta_as_u128)
			.ok_or(Error::<T>::NumOverflow)?;

		let total_borrowed_as_rate = Rate::from_inner(T::LiquidityPoolsManager::get_pool_total_borrowed(underlying_id));

		let borrow_amount = total_borrowed_as_rate
			.checked_div(&T::LiquidityPoolsManager::get_pool_borrow_index(underlying_id))
			.ok_or(Error::<T>::NumOverflow)?;

		let ratio = match borrow_amount.cmp(&Rate::zero()) {
			Ordering::Greater => Rate::from_inner(mnt_accrued)
				.checked_div(&borrow_amount)
				.ok_or(Error::<T>::NumOverflow)?,
			_ => Rate::zero(),
		};

		pool_state.borrow_state.mnt_distribution_index = pool_state
			.borrow_state
			.mnt_distribution_index
			.checked_add(&ratio)
			.ok_or(Error::<T>::NumOverflow)?;
		pool_state.borrow_state.index_updated_at_block = current_block;
		MntPoolsState::<T>::insert(underlying_id, pool_state);
		Ok(())
	}
/// Update mnt borrow index for pool
/// Do nothing in case if distribution is off or index have already been updated in this block.
Update mnt borrow index for pool
Do nothing in case if distribution is off or index have already been updated in this block.
Update mnt borrow index for pool Do nothing in case if distribution is off or index have already been updated in this block .
fn update_mnt_borrow_index(underlying_id: CurrencyId) -> DispatchResult {
		// block_delta = current_block_number - borrow_state.index_updated_at_block
		// mnt_accrued = delta_blocks * mnt_speed
		// borrow_amount - mtoken.total_borrows() / liquidity_pool_borrow_index
		// ratio = mnt_accrued / borrow_amount
		// borrow_state.mnt_distribution_index(for current pool) += ratio
		// borrow_state.index_updated_at_block = current_block_number
		let mnt_speed = MntSpeeds::<T>::get(underlying_id);
		if mnt_speed.is_zero() {
			// Distribution is off
			return Ok(());
		}
		let current_block = frame_system::Pallet::<T>::block_number();
		let mut pool_state = MntPoolsState::<T>::get(underlying_id);
		let block_delta = current_block
			.checked_sub(&pool_state.borrow_state.index_updated_at_block)
			.ok_or(Error::<T>::NumOverflow)?;
		if block_delta.is_zero() {
			// Index for current block was already calculated
			return Ok(());
		}
		let block_delta_as_u128 = TryInto::<u128>::try_into(block_delta).or(Err(Error::<T>::InternalError))?;
		let mnt_accrued = mnt_speed
			.checked_mul(block_delta_as_u128)
			.ok_or(Error::<T>::NumOverflow)?;
		let total_borrowed_as_rate = Rate::from_inner(T::LiquidityPoolsManager::get_pool_total_borrowed(underlying_id));
		let borrow_amount = total_borrowed_as_rate
			.checked_div(&T::LiquidityPoolsManager::get_pool_borrow_index(underlying_id))
			.ok_or(Error::<T>::NumOverflow)?;
		let ratio = match borrow_amount.cmp(&Rate::zero()) {
			Ordering::Greater => Rate::from_inner(mnt_accrued)
				.checked_div(&borrow_amount)
				.ok_or(Error::<T>::NumOverflow)?,
			_ => Rate::zero(),
		};
		pool_state.borrow_state.mnt_distribution_index = pool_state
			.borrow_state
			.mnt_distribution_index
			.checked_add(&ratio)
			.ok_or(Error::<T>::NumOverflow)?;
		pool_state.borrow_state.index_updated_at_block = current_block;
		MntPoolsState::<T>::insert(underlying_id, pool_state);
		Ok(())
	}
fn update_mnt_borrow_index ( underlying_id : CurrencyId ) -> DispatchResult { // block_delta = current_block_number - borrow_state.index_updated_at_block // mnt_accrued = delta_blocks * mnt_speed // borrow_amount - mtoken.total_borrows() / liquidity_pool_borrow_index // ratio = mnt_accrued / borrow_amount // borrow_state.mnt_distribution_index(for current pool) += ratio // borrow_state.index_updated_at_block = current_block_number let mnt_speed = MntSpeeds :: < T > :: get ( underlying_id ) ; if mnt_speed . is_zero ( ) { // Distribution is off return Ok ( ( ) ) ; } let current_block = frame_system :: Pallet :: < T > :: block_number ( ) ; let mut pool_state = MntPoolsState :: < T > :: get ( underlying_id ) ; let block_delta = current_block . checked_sub ( & pool_state . borrow_state . index_updated_at_block ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; if block_delta . is_zero ( ) { // Index for current block was already calculated return Ok ( ( ) ) ; } let block_delta_as_u128 = TryInto :: < u128 > :: try_into ( block_delta ) . or ( Err ( Error :: < T > :: InternalError ) ) ? ; let mnt_accrued = mnt_speed . checked_mul ( block_delta_as_u128 ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let total_borrowed_as_rate = Rate :: from_inner ( T :: LiquidityPoolsManager :: get_pool_total_borrowed ( underlying_id ) ) ; let borrow_amount = total_borrowed_as_rate . checked_div ( & T :: LiquidityPoolsManager :: get_pool_borrow_index ( underlying_id ) ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let ratio = match borrow_amount . cmp ( & Rate :: zero ( ) ) { Ordering :: Greater => Rate :: from_inner ( mnt_accrued ) . checked_div ( & borrow_amount ) . ok_or ( Error :: < T > :: NumOverflow ) ? , _ => Rate :: zero ( ) , } ; pool_state . borrow_state . mnt_distribution_index = pool_state . borrow_state . mnt_distribution_index . checked_add ( & ratio ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; pool_state . borrow_state . index_updated_at_block = current_block ; MntPoolsState :: < T > :: insert ( underlying_id , pool_state ) ; Ok ( ( ) ) }
Update mnt borrow index for pool
Do nothing in case if distribution is off or index have already been updated in this block.
Update mnt borrow index for pool Do nothing in case if distribution is off or index have already been updated in this block .
underlying_id
CurrencyId
underlying_id
CurrencyId