fn distribute_supplier_mnt(
		underlying_id: CurrencyId,
		supplier: &T::AccountId,
		distribute_all: bool,
	) -> BalanceResult {
		// delta_index = mnt_distribution_index - mnt_supplier_index
		// supplier_delta = supplier_mtoken_balance * delta_index
		// supplier_mnt_balance += supplier_delta
		// mnt_supplier_index = mnt_distribution_index
		let supply_index = MntPoolsState::<T>::get(underlying_id)
			.supply_state
			.mnt_distribution_index;

		let supplier_index = MntSupplierIndex::<T>::get(underlying_id, supplier).unwrap_or_else(Rate::one);

		let delta_index = supply_index
			.checked_sub(&supplier_index)
			.ok_or(Error::<T>::NumOverflow)?;

		let wrapped_asset_id = underlying_id
			.wrapped_asset()
			.ok_or(Error::<T>::NotValidUnderlyingAssetId)?;

		// We use total_balance (not free balance). Because sum of balances should be equal to
		// total_issuance. Otherwise, calculations will not be correct.
		// (see total_tokens_supply in update_mnt_supply_index)
		let supplier_balance = Rate::from_inner(T::MultiCurrency::total_balance(wrapped_asset_id, supplier));

		let supplier_delta = delta_index
			.checked_mul(&supplier_balance)
			.ok_or(Error::<T>::NumOverflow)?;

		let mut supplier_mnt_accrued = MntAccrued::<T>::get(supplier);

		supplier_mnt_accrued = supplier_mnt_accrued
			.checked_add(supplier_delta.into_inner())
			.ok_or(Error::<T>::NumOverflow)?;

		MntSupplierIndex::<T>::insert(underlying_id, supplier, supply_index);
		Self::transfer_mnt(supplier, supplier_mnt_accrued, distribute_all)?;

		Self::deposit_event(Event::MntDistributedToSupplier(
			underlying_id,
			supplier.clone(),
			supplier_delta.into_inner(),
			supply_index,
		));

		Ok(supplier_mnt_accrued)
	}
/// Distribute mnt token to supplier. It should be called after update_mnt_supply_index
Distribute mnt token to supplier. It should be called after update_mnt_supply_index
Distribute mnt token to supplier . It should be called after update_mnt_supply_index
fn distribute_supplier_mnt(
		underlying_id: CurrencyId,
		supplier: &T::AccountId,
		distribute_all: bool,
	) -> BalanceResult {
		// delta_index = mnt_distribution_index - mnt_supplier_index
		// supplier_delta = supplier_mtoken_balance * delta_index
		// supplier_mnt_balance += supplier_delta
		// mnt_supplier_index = mnt_distribution_index
		let supply_index = MntPoolsState::<T>::get(underlying_id)
			.supply_state
			.mnt_distribution_index;
		let supplier_index = MntSupplierIndex::<T>::get(underlying_id, supplier).unwrap_or_else(Rate::one);
		let delta_index = supply_index
			.checked_sub(&supplier_index)
			.ok_or(Error::<T>::NumOverflow)?;
		let wrapped_asset_id = underlying_id
			.wrapped_asset()
			.ok_or(Error::<T>::NotValidUnderlyingAssetId)?;
		// We use total_balance (not free balance). Because sum of balances should be equal to
		// total_issuance. Otherwise, calculations will not be correct.
		// (see total_tokens_supply in update_mnt_supply_index)
		let supplier_balance = Rate::from_inner(T::MultiCurrency::total_balance(wrapped_asset_id, supplier));
		let supplier_delta = delta_index
			.checked_mul(&supplier_balance)
			.ok_or(Error::<T>::NumOverflow)?;
		let mut supplier_mnt_accrued = MntAccrued::<T>::get(supplier);
		supplier_mnt_accrued = supplier_mnt_accrued
			.checked_add(supplier_delta.into_inner())
			.ok_or(Error::<T>::NumOverflow)?;
		MntSupplierIndex::<T>::insert(underlying_id, supplier, supply_index);
		Self::transfer_mnt(supplier, supplier_mnt_accrued, distribute_all)?;
		Self::deposit_event(Event::MntDistributedToSupplier(
			underlying_id,
			supplier.clone(),
			supplier_delta.into_inner(),
			supply_index,
		));
		Ok(supplier_mnt_accrued)
	}
fn distribute_supplier_mnt ( underlying_id : CurrencyId , supplier : & T :: AccountId , distribute_all : bool , ) -> BalanceResult { // delta_index = mnt_distribution_index - mnt_supplier_index // supplier_delta = supplier_mtoken_balance * delta_index // supplier_mnt_balance += supplier_delta // mnt_supplier_index = mnt_distribution_index let supply_index = MntPoolsState :: < T > :: get ( underlying_id ) . supply_state . mnt_distribution_index ; let supplier_index = MntSupplierIndex :: < T > :: get ( underlying_id , supplier ) . unwrap_or_else ( Rate :: one ) ; let delta_index = supply_index . checked_sub ( & supplier_index ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let wrapped_asset_id = underlying_id . wrapped_asset ( ) . ok_or ( Error :: < T > :: NotValidUnderlyingAssetId ) ? ; // We use total_balance (not free balance). Because sum of balances should be equal to // total_issuance. Otherwise, calculations will not be correct. // (see total_tokens_supply in update_mnt_supply_index) let supplier_balance = Rate :: from_inner ( T :: MultiCurrency :: total_balance ( wrapped_asset_id , supplier ) ) ; let supplier_delta = delta_index . checked_mul ( & supplier_balance ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let mut supplier_mnt_accrued = MntAccrued :: < T > :: get ( supplier ) ; supplier_mnt_accrued = supplier_mnt_accrued . checked_add ( supplier_delta . into_inner ( ) ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; MntSupplierIndex :: < T > :: insert ( underlying_id , supplier , supply_index ) ; Self :: transfer_mnt ( supplier , supplier_mnt_accrued , distribute_all ) ? ; Self :: deposit_event ( Event :: MntDistributedToSupplier ( underlying_id , supplier . clone ( ) , supplier_delta . into_inner ( ) , supply_index , ) ) ; Ok ( supplier_mnt_accrued ) }
Distribute mnt token to supplier.
Distribute mnt token to supplier .
underlying_id
CurrencyId
supplier
&T::AccountId
distribute_all
bool
underlying_id
CurrencyId
supplier
&T::AccountId
distribute_all
bool