pub fn calc_ppm_expiry_fee(
fee_chargeable_amount: Option<Amount>,
ppm_expiry_table: &Vec<PpmExpiryFeeEntry>,
vtxos: impl IntoIterator<Item = VtxoFeeInfo>,
) -> Option<Amount>Expand description
Calculates the total fee based on the provided fee-chargeable amount, a table of PPM (Parts Per Million) expiry-based fee rates, and an iterable list of VTXO information.
§Parameters
-
fee_chargeable_amount- An optional total amount from which the fee is chargeable. If specified, this amount determines the maximum amount to be used for fee calculations across all VTXOs. The value decreases as portions of it are consumed for each VTXOs fee calculation. IfNone, each VTXOs full amount is considered chargeable. -
ppm_expiry_table- Each entry contains an expiry threshold and a corresponding PPM fee. This table is assumed to be sorted in ascending order ofexpiry_blocks_thresholdfor correct behavior. -
vtxos- An iterable input ofVtxoFeeInfo, where each element contains the amount and the number of blocks until the VTXO expires, which is relevant for fee calculation.
§Returns
Returns an Amount representing the total calculated fee based on the provided inputs. None
if an overflow occurs.
§Example Usage
use ark::fees::{PpmExpiryFeeEntry, PpmFeeRate, VtxoFeeInfo, calc_ppm_expiry_fee};
use bitcoin::Amount;
let fee_chargeable_amount = Some(Amount::from_sat(15_000));
let ppm_expiry_table = vec![
PpmExpiryFeeEntry { expiry_blocks_threshold: 10, ppm: PpmFeeRate::ONE_PERCENT },
PpmExpiryFeeEntry { expiry_blocks_threshold: 20, ppm: PpmFeeRate(50_000) }, // 5%
];
let vtxos = vec![
VtxoFeeInfo { amount: Amount::from_sat(5_000), expiry_blocks: 2 },
VtxoFeeInfo { amount: Amount::from_sat(3_000), expiry_blocks: 12 },
VtxoFeeInfo { amount: Amount::from_sat(7_000), expiry_blocks: 22 },
];
let total_fee = calc_ppm_expiry_fee(fee_chargeable_amount, &ppm_expiry_table, vtxos);
assert_eq!(total_fee, Some(Amount::from_sat(380))); // 5,000 * 0% + 3,000 * 1% + 7,000 * 5% = 380