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:
Gavin Wood
2021-03-16 13:03:58 +01:00
committed by GitHub
parent b6c626399e
commit 363db4f086
32 changed files with 342 additions and 226 deletions
@@ -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,
);