fn update_mnt_supply_index(underlying_id: CurrencyId) -> DispatchResult {
		// block_delta = current_block_number - supply_state.index_updated_at_block
		// mnt_accrued = block_delta * mnt_speed
		// ratio = mnt_accrued / mtoken.total_supply()
		// supply_state.mnt_distribution_index += ratio
		// supply_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.supply_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 wrapped_asset_id = underlying_id
			.wrapped_asset()
			.ok_or(Error::<T>::NotValidUnderlyingAssetId)?;

		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_tokens_supply = T::MultiCurrency::total_issuance(wrapped_asset_id);

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

		pool_state.supply_state.mnt_distribution_index = pool_state
			.supply_state
			.mnt_distribution_index
			.checked_add(&ratio)
			.ok_or(Error::<T>::NumOverflow)?;
		pool_state.supply_state.index_updated_at_block = current_block;
		MntPoolsState::<T>::insert(underlying_id, pool_state);
		Ok(())
	}
/// Update mnt supply index for pool
/// Do nothing in case if distribution is off or index have already been updated in this block.
Update mnt supply index for pool
Do nothing in case if distribution is off or index have already been updated in this block.
Update mnt supply index for pool Do nothing in case if distribution is off or index have already been updated in this block .
fn update_mnt_supply_index(underlying_id: CurrencyId) -> DispatchResult {
		// block_delta = current_block_number - supply_state.index_updated_at_block
		// mnt_accrued = block_delta * mnt_speed
		// ratio = mnt_accrued / mtoken.total_supply()
		// supply_state.mnt_distribution_index += ratio
		// supply_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.supply_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 wrapped_asset_id = underlying_id
			.wrapped_asset()
			.ok_or(Error::<T>::NotValidUnderlyingAssetId)?;
		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_tokens_supply = T::MultiCurrency::total_issuance(wrapped_asset_id);
		let ratio = match total_tokens_supply.cmp(&Balance::zero()) {
			Ordering::Greater => {
				Rate::checked_from_rational(mnt_accrued, total_tokens_supply).ok_or(Error::<T>::NumOverflow)?
			}
			_ => Rate::zero(),
		};
		pool_state.supply_state.mnt_distribution_index = pool_state
			.supply_state
			.mnt_distribution_index
			.checked_add(&ratio)
			.ok_or(Error::<T>::NumOverflow)?;
		pool_state.supply_state.index_updated_at_block = current_block;
		MntPoolsState::<T>::insert(underlying_id, pool_state);
		Ok(())
	}
fn update_mnt_supply_index ( underlying_id : CurrencyId ) -> DispatchResult { // block_delta = current_block_number - supply_state.index_updated_at_block // mnt_accrued = block_delta * mnt_speed // ratio = mnt_accrued / mtoken.total_supply() // supply_state.mnt_distribution_index += ratio // supply_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 . supply_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 wrapped_asset_id = underlying_id . wrapped_asset ( ) . ok_or ( Error :: < T > :: NotValidUnderlyingAssetId ) ? ; 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_tokens_supply = T :: MultiCurrency :: total_issuance ( wrapped_asset_id ) ; let ratio = match total_tokens_supply . cmp ( & Balance :: zero ( ) ) { Ordering :: Greater => { Rate :: checked_from_rational ( mnt_accrued , total_tokens_supply ) . ok_or ( Error :: < T > :: NumOverflow ) ? } _ => Rate :: zero ( ) , } ; pool_state . supply_state . mnt_distribution_index = pool_state . supply_state . mnt_distribution_index . checked_add ( & ratio ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; pool_state . supply_state . index_updated_at_block = current_block ; MntPoolsState :: < T > :: insert ( underlying_id , pool_state ) ; Ok ( ( ) ) }
Update mnt supply index for pool
Do nothing in case if distribution is off or index have already been updated in this block.
Update mnt supply 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