Skip to content
Snippets Groups Projects
Commit ecf2bb16 authored by Éloïs's avatar Éloïs
Browse files

ref(pallet_ud): use pallet constant for ud params

parent 25a7353f
No related branches found
No related tags found
No related merge requests found
......@@ -63,8 +63,7 @@ tag = 'monthly-2021-07'
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
[dev-dependencies.serde]
version = '1.0.119'
### DEV ###
......@@ -73,6 +72,10 @@ default-features = false
git = 'https://github.com/paritytech/substrate.git'
tag = 'monthly-2021-07'
[dev-dependencies.serde]
features = ["derive"]
version = '1.0.119'
[dev-dependencies.sp-core]
default-features = false
git = 'https://github.com/paritytech/substrate.git'
......
......@@ -44,13 +44,16 @@ pub mod pallet {
#[pallet::config]
pub trait Config: frame_system::Config {
#[pallet::constant]
/// Universal dividend creation period
const UD_CREATION_PERIOD: Self::BlockNumber;
type UdCreationPeriod: Get<Self::BlockNumber>;
#[pallet::constant]
/// Universal dividend reevaluation period (in number of creation period)
const UD_REEVAL_PERIOD: BalanceOf<Self>;
type UdReevalPeriod: Get<BalanceOf<Self>>;
#[pallet::constant]
/// Universal dividend reevaluation period in number of blocks
/// Must be equal to UD_CREATION_PERIOD * UD_REEVAl_PERIOD
const UD_REEVAL_PERIOD_IN_BLOCKS: Self::BlockNumber;
/// Must be equal to UdReevalPeriod * UdCreationPeriod
type UdReevalPeriodInBlocks: Get<Self::BlockNumber>;
// The currency
type Currency: Currency<Self::AccountId>;
......@@ -153,9 +156,9 @@ pub mod pallet {
#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_initialize(n: T::BlockNumber) -> Weight {
if (n % T::UD_CREATION_PERIOD).is_zero() {
if (n % T::UdCreationPeriod::get()).is_zero() {
let current_members_count = T::MembersCount::get();
if (n % T::UD_REEVAL_PERIOD_IN_BLOCKS).is_zero() {
if (n % T::UdReevalPeriodInBlocks::get()).is_zero() {
Self::reeval_ud(current_members_count)
+ Self::create_ud(current_members_count, n)
} else {
......@@ -221,7 +224,7 @@ pub mod pallet {
T::SquareMoneyGrowthRate::get(),
monetary_mass,
members_count,
T::UD_REEVAL_PERIOD,
T::UdReevalPeriod::get(),
);
Self::deposit_event(Event::UdReevalued(
......
......@@ -29,6 +29,7 @@ use sp_runtime::{
};
type Balance = u64;
type BlockNumber = u64;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
......@@ -96,6 +97,9 @@ impl pallet_balances::Config for Test {
parameter_types! {
pub const MembersCount: u64 = 3;
pub const SquareMoneyGrowthRate: Permill = Permill::from_percent(10);
pub const UdCreationPeriod: BlockNumber = 2;
pub const UdReevalPeriod: Balance = 4;
pub const UdReevalPeriodInBlocks: BlockNumber = 8; // 2 * 4
}
pub struct FakeWot;
......@@ -106,15 +110,14 @@ impl Get<Vec<u64>> for FakeWot {
}
impl pallet_universal_dividend::Config for Test {
const UD_CREATION_PERIOD: Self::BlockNumber = 2;
const UD_REEVAL_PERIOD: Balance = 4;
const UD_REEVAL_PERIOD_IN_BLOCKS: Self::BlockNumber = 8; // 2 * 4
type Currency = pallet_balances::Pallet<Test>;
type Event = Event;
type MembersCount = MembersCount;
type MembersIds = FakeWot;
type SquareMoneyGrowthRate = SquareMoneyGrowthRate;
type UdCreationPeriod = UdCreationPeriod;
type UdReevalPeriod = UdReevalPeriod;
type UdReevalPeriodInBlocks = UdReevalPeriodInBlocks;
}
// Build genesis storage according to the mock runtime.
......
......@@ -376,6 +376,9 @@ impl pallet_certification::Config for Runtime {
parameter_types! {
pub const SquareMoneyGrowthRate: Permill = Permill::one();
pub const UdCreationPeriod: BlockNumber = 20;
pub const UdReevalPeriod: Balance = 10;
pub const UdReevalPeriodInBlocks: BlockNumber = 20 * 10;
}
pub struct UdAccountsProvider;
......@@ -392,16 +395,14 @@ impl Get<Vec<AccountId>> for UdAccountsProvider {
/// Configure the pallet universal-dividend in pallets/universal-dividend.
impl pallet_universal_dividend::Config for Runtime {
const UD_CREATION_PERIOD: Self::BlockNumber = 20;
const UD_REEVAL_PERIOD: Balance = 10;
const UD_REEVAL_PERIOD_IN_BLOCKS: Self::BlockNumber =
Self::UD_CREATION_PERIOD * Self::UD_REEVAL_PERIOD as Self::BlockNumber;
type Currency = pallet_balances::Pallet<Runtime>;
type Event = Event;
type MembersCount = UdAccountsProvider;
type MembersIds = UdAccountsProvider;
type SquareMoneyGrowthRate = SquareMoneyGrowthRate;
type UdCreationPeriod = UdCreationPeriod;
type UdReevalPeriod = UdReevalPeriod;
type UdReevalPeriodInBlocks = UdReevalPeriodInBlocks;
}
/// Configure the pallet ud-accounts-storage
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment