fn distribute_borrower_mnt(
		underlying_id: CurrencyId,
		borrower: &T::AccountId,
		distribute_all: bool,
	) -> BalanceResult {
		// borrower_amount = account_borrow_balance / liquidity_pool_borrow_index
		// delta_index = mnt_distribution_index(for current pool) - borrower_index
		// borrower_delta = borrower_amount * delta_index
		// borrower_accrued += borrower_delta
		// borrower_index = mnt_distribution_index(for current pool)

		let borrower_index = MntBorrowerIndex::<T>::get(underlying_id, borrower);
		let pool_borrow_state = MntPoolsState::<T>::get(underlying_id).borrow_state;
		// Update borrower index
		MntBorrowerIndex::<T>::insert(underlying_id, borrower, pool_borrow_state.mnt_distribution_index);
		if borrower_index.is_zero() {
			// This is first interaction with protocol
			return Ok(Balance::zero());
		}

		let borrow_balance = T::ControllerManager::borrow_balance_stored(&borrower, underlying_id)?;
		let pool_borrow_index = T::LiquidityPoolsManager::get_pool_borrow_index(underlying_id);
		let borrower_amount = Price::from_inner(borrow_balance)
			.checked_div(&pool_borrow_index)
			.ok_or(Error::<T>::NumOverflow)?;

		let delta_index = pool_borrow_state
			.mnt_distribution_index
			.checked_sub(&borrower_index)
			.ok_or(Error::<T>::NumOverflow)?;

		if delta_index == Rate::zero() {
			return Ok(Balance::zero());
		}

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

		let mut borrower_mnt_accrued = MntAccrued::<T>::get(borrower);
		borrower_mnt_accrued = borrower_mnt_accrued
			.checked_add(borrower_delta.into_inner())
			.ok_or(Error::<T>::NumOverflow)?;

		Self::transfer_mnt(borrower, borrower_mnt_accrued, distribute_all)?;

		Self::deposit_event(Event::MntDistributedToBorrower(
			underlying_id,
			borrower.clone(),
			borrower_delta.into_inner(),
			pool_borrow_state.mnt_distribution_index,
		));
		Ok(borrower_mnt_accrued)
	}
/// Distribute MNT token to borrower. It should be called after update_mnt_borrow_index.
/// Borrowers will not begin to accrue tokens till the first interaction with the protocol.
///
/// - `underlying_id`: The pool in which the borrower is acting;
/// - `borrower`: The AccountId of the borrower to distribute MNT to.
Distribute MNT token to borrower. It should be called after update_mnt_borrow_index.
Borrowers will not begin to accrue tokens till the first interaction with the protocol.

`underlying_id`: The pool in which the borrower is acting;
`borrower`: The AccountId of the borrower to distribute MNT to.
Distribute MNT token to borrower . It should be called after update_mnt_borrow_index . Borrowers will not begin to accrue tokens till the first interaction with the protocol . ` underlying_id ` : The pool in which the borrower is acting ; ` borrower ` : The AccountId of the borrower to distribute MNT to .
fn distribute_borrower_mnt(
		underlying_id: CurrencyId,
		borrower: &T::AccountId,
		distribute_all: bool,
	) -> BalanceResult {
		// borrower_amount = account_borrow_balance / liquidity_pool_borrow_index
		// delta_index = mnt_distribution_index(for current pool) - borrower_index
		// borrower_delta = borrower_amount * delta_index
		// borrower_accrued += borrower_delta
		// borrower_index = mnt_distribution_index(for current pool)
		let borrower_index = MntBorrowerIndex::<T>::get(underlying_id, borrower);
		let pool_borrow_state = MntPoolsState::<T>::get(underlying_id).borrow_state;
		// Update borrower index
		MntBorrowerIndex::<T>::insert(underlying_id, borrower, pool_borrow_state.mnt_distribution_index);
		if borrower_index.is_zero() {
			// This is first interaction with protocol
			return Ok(Balance::zero());
		}
		let borrow_balance = T::ControllerManager::borrow_balance_stored(&borrower, underlying_id)?;
		let pool_borrow_index = T::LiquidityPoolsManager::get_pool_borrow_index(underlying_id);
		let borrower_amount = Price::from_inner(borrow_balance)
			.checked_div(&pool_borrow_index)
			.ok_or(Error::<T>::NumOverflow)?;
		let delta_index = pool_borrow_state
			.mnt_distribution_index
			.checked_sub(&borrower_index)
			.ok_or(Error::<T>::NumOverflow)?;
		if delta_index == Rate::zero() {
			return Ok(Balance::zero());
		}
		let borrower_delta = borrower_amount
			.checked_mul(&delta_index)
			.ok_or(Error::<T>::NumOverflow)?;
		let mut borrower_mnt_accrued = MntAccrued::<T>::get(borrower);
		borrower_mnt_accrued = borrower_mnt_accrued
			.checked_add(borrower_delta.into_inner())
			.ok_or(Error::<T>::NumOverflow)?;
		Self::transfer_mnt(borrower, borrower_mnt_accrued, distribute_all)?;
		Self::deposit_event(Event::MntDistributedToBorrower(
			underlying_id,
			borrower.clone(),
			borrower_delta.into_inner(),
			pool_borrow_state.mnt_distribution_index,
		));
		Ok(borrower_mnt_accrued)
	}
fn distribute_borrower_mnt ( underlying_id : CurrencyId , borrower : & T :: AccountId , distribute_all : bool , ) -> BalanceResult { // borrower_amount = account_borrow_balance / liquidity_pool_borrow_index // delta_index = mnt_distribution_index(for current pool) - borrower_index // borrower_delta = borrower_amount * delta_index // borrower_accrued += borrower_delta // borrower_index = mnt_distribution_index(for current pool) let borrower_index = MntBorrowerIndex :: < T > :: get ( underlying_id , borrower ) ; let pool_borrow_state = MntPoolsState :: < T > :: get ( underlying_id ) . borrow_state ; // Update borrower index MntBorrowerIndex :: < T > :: insert ( underlying_id , borrower , pool_borrow_state . mnt_distribution_index ) ; if borrower_index . is_zero ( ) { // This is first interaction with protocol return Ok ( Balance :: zero ( ) ) ; } let borrow_balance = T :: ControllerManager :: borrow_balance_stored ( & borrower , underlying_id ) ? ; let pool_borrow_index = T :: LiquidityPoolsManager :: get_pool_borrow_index ( underlying_id ) ; let borrower_amount = Price :: from_inner ( borrow_balance ) . checked_div ( & pool_borrow_index ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let delta_index = pool_borrow_state . mnt_distribution_index . checked_sub ( & borrower_index ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; if delta_index == Rate :: zero ( ) { return Ok ( Balance :: zero ( ) ) ; } let borrower_delta = borrower_amount . checked_mul ( & delta_index ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; let mut borrower_mnt_accrued = MntAccrued :: < T > :: get ( borrower ) ; borrower_mnt_accrued = borrower_mnt_accrued . checked_add ( borrower_delta . into_inner ( ) ) . ok_or ( Error :: < T > :: NumOverflow ) ? ; Self :: transfer_mnt ( borrower , borrower_mnt_accrued , distribute_all ) ? ; Self :: deposit_event ( Event :: MntDistributedToBorrower ( underlying_id , borrower . clone ( ) , borrower_delta . into_inner ( ) , pool_borrow_state . mnt_distribution_index , ) ) ; Ok ( borrower_mnt_accrued ) }
Distribute MNT token to borrower.
Distribute MNT token to borrower .
underlying_id
CurrencyId
borrower
&T::AccountId
distribute_all
bool
underlying_id
CurrencyId
borrower
&T::AccountId
distribute_all
bool