Math helper functions


Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR as 10000. Precision on default functions is rounded down to the nearest 0.1 and the lowest percentage is 0.01 as 1. Precision on the round_up functions is rounded up to the nearest 0.1.


pub fn percent_mul(x: u128, y: u128) -> u128


pub fn percent_div(x: u128, y: u128) -> u128

Multiply Round-Up

pub fn percent_mul_round_up(x: u128, y: u128) -> u128

Divide Round-Up

pub fn percent_div_round_up(x: u128, y: u128) -> u128

Inspired by Aave's PercentageMath with modifications

Last updated