diff --git a/pallets/universal-dividend/Cargo.toml b/pallets/universal-dividend/Cargo.toml index 046a9dc66e5065ab4b5bbe83d8e940293b28f21e..982a4ff60e9f84f37487f0e874ba1d16d3ba487a 100644 --- a/pallets/universal-dividend/Cargo.toml +++ b/pallets/universal-dividend/Cargo.toml @@ -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' diff --git a/pallets/universal-dividend/src/lib.rs b/pallets/universal-dividend/src/lib.rs index 0e1015c412525c706968d387b33a1e44e8fe34e2..e6e55b9bbf81b5637a2dff3798ba434200262c96 100644 --- a/pallets/universal-dividend/src/lib.rs +++ b/pallets/universal-dividend/src/lib.rs @@ -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( diff --git a/pallets/universal-dividend/src/mock.rs b/pallets/universal-dividend/src/mock.rs index e82ea28f104976bae7b6a5c819443897e0767205..9d1e5d8a763a7e3fa03d6204fdc18280f71eec68 100644 --- a/pallets/universal-dividend/src/mock.rs +++ b/pallets/universal-dividend/src/mock.rs @@ -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. diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 335a7af901fd20f87471936be24c8393370186c0..0ddf09043ed804cd83658b90cb198f501c33dfe1 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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