mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 02:57:57 +00:00
staking: Flexible generation of reward curve and associated tweaks (#8327)
* Initial abstraction * Alter rest of APIs * Fixes * Some extra getters in Gilt pallet. * Refactor Gilt to avoid u128 conversions * Simplify and improve pow in per_things * Add scalar division to per_things * Renaming from_fraction -> from_float, drop _approximation * Fixes * Fixes * Fixes * Fixes * Make stuff build * Fixes * Fixes * Fixes * Fixes * Update .gitignore Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/gilt/src/lib.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Update frame/gilt/src/mock.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> * Fixes * Fixes * Fixes Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
@@ -38,75 +38,75 @@ fn main() {
|
||||
|
||||
// peru16
|
||||
let (smaller, bigger) = (u16_pair.0.min(u16_pair.1), u16_pair.0.max(u16_pair.1));
|
||||
let ratio = PerU16::from_rational_approximation(smaller, bigger);
|
||||
let ratio = PerU16::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
PerU16::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
PerU16::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1,
|
||||
);
|
||||
let (smaller, bigger) = (u32_pair.0.min(u32_pair.1), u32_pair.0.max(u32_pair.1));
|
||||
let ratio = PerU16::from_rational_approximation(smaller, bigger);
|
||||
let ratio = PerU16::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
PerU16::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
PerU16::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1,
|
||||
);
|
||||
let (smaller, bigger) = (u64_pair.0.min(u64_pair.1), u64_pair.0.max(u64_pair.1));
|
||||
let ratio = PerU16::from_rational_approximation(smaller, bigger);
|
||||
let ratio = PerU16::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
PerU16::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
PerU16::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1,
|
||||
);
|
||||
|
||||
// percent
|
||||
let (smaller, bigger) = (u16_pair.0.min(u16_pair.1), u16_pair.0.max(u16_pair.1));
|
||||
let ratio = Percent::from_rational_approximation(smaller, bigger);
|
||||
let ratio = Percent::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
Percent::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
Percent::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1,
|
||||
);
|
||||
|
||||
let (smaller, bigger) = (u32_pair.0.min(u32_pair.1), u32_pair.0.max(u32_pair.1));
|
||||
let ratio = Percent::from_rational_approximation(smaller, bigger);
|
||||
let ratio = Percent::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
Percent::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
Percent::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1,
|
||||
);
|
||||
|
||||
let (smaller, bigger) = (u64_pair.0.min(u64_pair.1), u64_pair.0.max(u64_pair.1));
|
||||
let ratio = Percent::from_rational_approximation(smaller, bigger);
|
||||
let ratio = Percent::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
Percent::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
Percent::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1,
|
||||
);
|
||||
|
||||
// perbill
|
||||
let (smaller, bigger) = (u32_pair.0.min(u32_pair.1), u32_pair.0.max(u32_pair.1));
|
||||
let ratio = Perbill::from_rational_approximation(smaller, bigger);
|
||||
let ratio = Perbill::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
Perbill::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
Perbill::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
100,
|
||||
);
|
||||
|
||||
let (smaller, bigger) = (u64_pair.0.min(u64_pair.1), u64_pair.0.max(u64_pair.1));
|
||||
let ratio = Perbill::from_rational_approximation(smaller, bigger);
|
||||
let ratio = Perbill::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
Perbill::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
Perbill::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
100,
|
||||
);
|
||||
|
||||
// perquintillion
|
||||
let (smaller, bigger) = (u64_pair.0.min(u64_pair.1), u64_pair.0.max(u64_pair.1));
|
||||
let ratio = Perquintill::from_rational_approximation(smaller, bigger);
|
||||
let ratio = Perquintill::from_rational(smaller, bigger);
|
||||
assert_per_thing_equal_error(
|
||||
ratio,
|
||||
Perquintill::from_fraction(smaller as f64 / bigger.max(1) as f64),
|
||||
Perquintill::from_float(smaller as f64 / bigger.max(1) as f64),
|
||||
1000,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user