pub(crate) fn update_exchange_rate(asset_id: AssetIdOf<T>) -> DispatchResult {
        let total_supply = Self::total_supply(asset_id);
        if total_supply.is_zero() {
            return Ok(());
        }
        let total_cash = Self::get_total_cash(asset_id);
        let total_borrows = Self::total_borrows(asset_id);
        let total_reserves = Self::total_reserves(asset_id);

        let cash_plus_borrows_minus_reserves = total_cash
            .checked_add(total_borrows)
            .and_then(|r| r.checked_sub(total_reserves))
            .ok_or(ArithmeticError::Overflow)?;
        let exchange_rate =
            Rate::checked_from_rational(cash_plus_borrows_minus_reserves, total_supply)
                .ok_or(ArithmeticError::Underflow)?;

        ExchangeRate::<T>::insert(asset_id, exchange_rate);

        Ok(())
    }
/// Update the exchange rate according to the totalCash, totalBorrows and totalSupply.
///
/// exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
Update the exchange rate according to the totalCash, totalBorrows and totalSupply.
exchangeRate = (totalCash + totalBorrows - totalReserves) / totalSupply
Update the exchange rate according to the totalCash totalBorrows and totalSupply . exchangeRate = ( totalCash + totalBorrows - totalReserves ) / totalSupply
pub(crate) fn update_exchange_rate(asset_id: AssetIdOf<T>) -> DispatchResult {
        let total_supply = Self::total_supply(asset_id);
        if total_supply.is_zero() {
            return Ok(());
        }
        let total_cash = Self::get_total_cash(asset_id);
        let total_borrows = Self::total_borrows(asset_id);
        let total_reserves = Self::total_reserves(asset_id);
        let cash_plus_borrows_minus_reserves = total_cash
            .checked_add(total_borrows)
            .and_then(|r| r.checked_sub(total_reserves))
            .ok_or(ArithmeticError::Overflow)?;
        let exchange_rate =
            Rate::checked_from_rational(cash_plus_borrows_minus_reserves, total_supply)
                .ok_or(ArithmeticError::Underflow)?;
        ExchangeRate::<T>::insert(asset_id, exchange_rate);
        Ok(())
    }
pub ( crate ) fn update_exchange_rate ( asset_id : AssetIdOf < T > ) -> DispatchResult { let total_supply = Self :: total_supply ( asset_id ) ; if total_supply . is_zero ( ) { return Ok ( ( ) ) ; } let total_cash = Self :: get_total_cash ( asset_id ) ; let total_borrows = Self :: total_borrows ( asset_id ) ; let total_reserves = Self :: total_reserves ( asset_id ) ; let cash_plus_borrows_minus_reserves = total_cash . checked_add ( total_borrows ) . and_then ( | r | r . checked_sub ( total_reserves ) ) . ok_or ( ArithmeticError :: Overflow ) ? ; let exchange_rate = Rate :: checked_from_rational ( cash_plus_borrows_minus_reserves , total_supply ) . ok_or ( ArithmeticError :: Underflow ) ? ; ExchangeRate :: < T > :: insert ( asset_id , exchange_rate ) ; Ok ( ( ) ) }
Update the exchange rate according to the totalCash, totalBorrows and totalSupply.
Update the exchange rate according to the totalCash totalBorrows and totalSupply .
asset_id
AssetIdOf<T>
asset_id
AssetIdOf<T>