Expand description
Ppm - parts per million newtype for proportional fee rates.
A “parts per million” (ppm) newtype for proportional fee rates.
PPM values represent a proportion where 1_000_000 ppm = 100%. Valid range: 0 to 1_000_000 inclusive.
§Calculating fees
Multiply an Amount by a
Ppm to get the fee:
let amount = Amount::from_sats_u32(100_000);
let fee_rate = Ppm::new(3000); // 0.3%
let fee = amount * fee_rate;
assert_eq!(fee, Amount::from_sats_u32(300));§Defining constants
Use the ppm! macro for convenient compile-time validated constants:
const A_FEE_RATE_PPM: Ppm = ppm!(3000); // 0.3%
const B_FEE_RATE_PPM: Ppm = ppm!(0.3%); // 0.3%
const C_FEE_RATE_DEC: Decimal = ppm!(3000).to_decimal(); // 0.3%§Converting to a decimal rate or percentage
Ppm::to_decimal returns a
Decimal rate, while
Ppm::to_percent returns a percentage:
let ppm = ppm!(5000);
assert_eq!(ppm.to_decimal(), dec!(0.005));
assert_eq!(ppm.to_percent(), dec!(0.5));Structs§
- Ppm
- A “parts per million” value for proportional fee rates.