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