use super::RoyaltyRecipient;
use crate::internal_prelude::*;
use radix_engine_interface::blueprints::resource::LiquidFungibleResource;
use sbor::rust::collections::*;
#[derive(Default, Debug, Clone, ScryptoSbor)]
pub struct FeeReserveFinalizationSummary {
pub total_execution_cost_units_consumed: u32,
pub total_finalization_cost_units_consumed: u32,
pub total_execution_cost_in_xrd: Decimal,
pub total_finalization_cost_in_xrd: Decimal,
pub total_tipping_cost_in_xrd: Decimal,
pub total_storage_cost_in_xrd: Decimal,
pub total_royalty_cost_in_xrd: Decimal,
pub total_bad_debt_in_xrd: Decimal,
pub locked_fees: Vec<(NodeId, LiquidFungibleResource, bool)>,
pub royalty_cost_breakdown: IndexMap<RoyaltyRecipient, Decimal>,
}
impl FeeReserveFinalizationSummary {
pub fn loan_fully_repaid(&self) -> bool {
self.total_bad_debt_in_xrd == 0.into()
}
pub fn total_cost(&self) -> Decimal {
self.total_execution_cost_in_xrd
.checked_add(self.total_finalization_cost_in_xrd)
.unwrap()
.checked_add(self.total_tipping_cost_in_xrd)
.unwrap()
.checked_add(self.total_storage_cost_in_xrd)
.unwrap()
.checked_add(self.total_royalty_cost_in_xrd)
.unwrap()
}
pub fn network_fees(&self) -> Decimal {
self.total_execution_cost_in_xrd
.checked_add(self.total_finalization_cost_in_xrd)
.unwrap()
.checked_add(self.total_storage_cost_in_xrd)
.unwrap()
}
pub fn to_proposer_amount(&self) -> Decimal {
let one_percent = Decimal::ONE_HUNDREDTH;
self.total_tipping_cost_in_xrd
.checked_mul(
one_percent
.checked_mul(TIPS_PROPOSER_SHARE_PERCENTAGE)
.unwrap(),
)
.unwrap()
.checked_add(
self.network_fees()
.checked_mul(
one_percent
.checked_mul(NETWORK_FEES_PROPOSER_SHARE_PERCENTAGE)
.unwrap(),
)
.unwrap(),
)
.unwrap()
}
pub fn to_validator_set_amount(&self) -> Decimal {
let one_percent = Decimal::ONE_HUNDREDTH;
self.total_tipping_cost_in_xrd
.checked_mul(
one_percent
.checked_mul(TIPS_VALIDATOR_SET_SHARE_PERCENTAGE)
.unwrap(),
)
.unwrap()
.checked_add(
self.network_fees()
.checked_mul(
one_percent
.checked_mul(NETWORK_FEES_VALIDATOR_SET_SHARE_PERCENTAGE)
.unwrap(),
)
.unwrap(),
)
.unwrap()
}
pub fn to_burn_amount(&self) -> Decimal {
self.total_tipping_cost_in_xrd
.checked_add(self.network_fees())
.unwrap()
.checked_sub(self.to_proposer_amount())
.unwrap()
.checked_sub(self.to_validator_set_amount())
.unwrap()
}
}