pub fn calculate_borrow_fees(
        &self,
        collateral_amount: u64,
    ) -> Result<(u64, u64), ProgramError> {
        let borrow_fee_rate = Rate::from_scaled_val(self.borrow_fee_wad);
        let host_fee_rate = Rate::from_percent(self.host_fee_percentage);
        if borrow_fee_rate > Rate::zero() && collateral_amount > 0 {
            let need_to_assess_host_fee = host_fee_rate > Rate::zero();
            let minimum_fee = if need_to_assess_host_fee {
                2 // 1 token to owner, 1 to host
            } else {
                1 // 1 token to owner, nothing else
            };

            let borrow_fee = borrow_fee_rate
                .try_mul(collateral_amount)?
                .try_round_u64()?
                .max(minimum_fee);

            let host_fee = if need_to_assess_host_fee {
                host_fee_rate.try_mul(borrow_fee)?.try_round_u64()?.max(1)
            } else {
                0
            };

            if borrow_fee >= collateral_amount {
                Err(LendingError::BorrowTooSmall.into())
            } else {
                Ok((borrow_fee, host_fee))
            }
        } else {
            Ok((0, 0))
        }
    }
/// Calculate the owner and host fees on borrow
Calculate the owner and host fees on borrow
Calculate the owner and host fees on borrow
pub fn calculate_borrow_fees(
        &self,
        collateral_amount: u64,
    ) -> Result<(u64, u64), ProgramError> {
        let borrow_fee_rate = Rate::from_scaled_val(self.borrow_fee_wad);
        let host_fee_rate = Rate::from_percent(self.host_fee_percentage);
        if borrow_fee_rate > Rate::zero() && collateral_amount > 0 {
            let need_to_assess_host_fee = host_fee_rate > Rate::zero();
            let minimum_fee = if need_to_assess_host_fee {
                2 // 1 token to owner, 1 to host
            } else {
                1 // 1 token to owner, nothing else
            };
            let borrow_fee = borrow_fee_rate
                .try_mul(collateral_amount)?
                .try_round_u64()?
                .max(minimum_fee);
            let host_fee = if need_to_assess_host_fee {
                host_fee_rate.try_mul(borrow_fee)?.try_round_u64()?.max(1)
            } else {
                0
            };
            if borrow_fee >= collateral_amount {
                Err(LendingError::BorrowTooSmall.into())
            } else {
                Ok((borrow_fee, host_fee))
            }
        } else {
            Ok((0, 0))
        }
    }
pub fn calculate_borrow_fees ( & self , collateral_amount : u64 , ) -> Result < ( u64 , u64 ) , ProgramError > { let borrow_fee_rate = Rate :: from_scaled_val ( self . borrow_fee_wad ) ; let host_fee_rate = Rate :: from_percent ( self . host_fee_percentage ) ; if borrow_fee_rate > Rate :: zero ( ) && collateral_amount > 0 { let need_to_assess_host_fee = host_fee_rate > Rate :: zero ( ) ; let minimum_fee = if need_to_assess_host_fee { 2 // 1 token to owner, 1 to host } else { 1 // 1 token to owner, nothing else } ; let borrow_fee = borrow_fee_rate . try_mul ( collateral_amount ) ? . try_round_u64 ( ) ? . max ( minimum_fee ) ; let host_fee = if need_to_assess_host_fee { host_fee_rate . try_mul ( borrow_fee ) ? . try_round_u64 ( ) ? . max ( 1 ) } else { 0 } ; if borrow_fee >= collateral_amount { Err ( LendingError :: BorrowTooSmall . into ( ) ) } else { Ok ( ( borrow_fee , host_fee ) ) } } else { Ok ( ( 0 , 0 ) ) } }
Calculate the owner and host fees on borrow
Calculate the owner and host fees on borrow
&self
collateral_amount
u64