Skip to main content

Module ppm

Module ppm 

Source
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 Ppm::new for compile-time validated constants:

const MY_FEE_RATE: Ppm = Ppm::new(3000); // 0.3%

§Converting to a decimal rate

Ppm::to_decimal returns a Decimal rate:

let rate = Ppm::new(5000).to_decimal(); // 0.5%
assert_eq!(rate, dec!(0.005));

Structs§

Ppm
A “parts per million” value for proportional fee rates.

Enums§

Error
Errors that can occur when constructing a Ppm.