Skip to content

Commit

Permalink
feat(242): small changes from Leonardo's feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Aug 18, 2023
1 parent 998c54b commit 3f8d287
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pallets/funding/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod config_types {
use crate::{traits::VestingDurationCalculation, Config};
use parachains_common::DAYS;
use sp_arithmetic::FixedU128;
use sp_arithmetic::traits::Saturating;
use sp_runtime::traits::{Convert, Zero};

#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen, Copy, Ord, PartialOrd)]
Expand All @@ -54,23 +55,24 @@ pub mod config_types {
Err(())
}
}
}
}

impl BondingRequirementCalculation for Multiplier {
fn calculate_bonding_requirement<T: Config>(&self, ticket_size: BalanceOf<T>) -> Result<BalanceOf<T>, ()> {
let u32_multiplier = self.0 as u32;
let balance_multiplier = BalanceOf::<T>::from(u32_multiplier);
let balance_multiplier = BalanceOf::<T>::from(self.0);
ticket_size.checked_div(&balance_multiplier).ok_or(())
}
}

impl VestingDurationCalculation for Multiplier {
fn calculate_vesting_duration<T: Config>(&self) -> T::BlockNumber {
let gradient = FixedU128::from_rational(2167u128, 1000u128);
let neg_constant = FixedU128::from_rational(2167u128, 1000u128);
let multiplier = FixedU128::saturating_from_integer(self.0);
let weeks = gradient * multiplier - neg_constant;
// gradient "m" of the linear curve function y = m*x + b
const GRADIENT: FixedU128 = FixedU128::from_rational(2167u128, 1000u128);
// negative constant (because we cannot have negative values, so we take the negative and do "-b" instead of "+b") "b" of the linear curve function y = m*x + b
const NEG_CONSTANT: FixedU128 = FixedU128::from_rational(2167u128, 1000u128);

let multiplier_as_fixed = FixedU128::saturating_from_integer(self.0);
let weeks = GRADIENT.saturating_mul(multiplier_as_fixed).saturating_sub(NEG_CONSTANT);
T::WeeksToBlocks::convert(weeks)
}
}
Expand Down

0 comments on commit 3f8d287

Please sign in to comment.