From b69cfff07e188a8a8460659a03a33158524c663e Mon Sep 17 00:00:00 2001 From: ndkazu Date: Tue, 6 Aug 2024 00:15:41 +0900 Subject: [PATCH] Distribution pallet README --- substrate/bin/node/runtime/src/lib.rs | 2 +- substrate/frame/distribution/README.md | 29 +++++++++++++++++++++++ substrate/frame/distribution/src/lib.rs | 4 ++-- substrate/frame/distribution/src/mock.rs | 2 +- substrate/frame/distribution/src/types.rs | 2 +- substrate/frame/opf/src/functions.rs | 4 ++-- 6 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 substrate/frame/distribution/README.md diff --git a/substrate/bin/node/runtime/src/lib.rs b/substrate/bin/node/runtime/src/lib.rs index 6aee376843f2..881414c847bd 100644 --- a/substrate/bin/node/runtime/src/lib.rs +++ b/substrate/bin/node/runtime/src/lib.rs @@ -2157,7 +2157,7 @@ impl pallet_distribution::Config for Runtime { /// This the minimum required time period between project whitelisting /// and payment/reward_claim from the treasury. - type PaymentPeriod = Period; + type BufferPeriod = Period; /// Maximum number of whitelisted projects type MaxProjects = MaxProjects; diff --git a/substrate/frame/distribution/README.md b/substrate/frame/distribution/README.md new file mode 100644 index 000000000000..b2e95ce5bebb --- /dev/null +++ b/substrate/frame/distribution/README.md @@ -0,0 +1,29 @@ +# Distribution Pallet +## Overview + +The **Distribution Pallet** handles the distribution of whitelisted projects rewards. + +For now only one reward distribution pattern has been implemented, but the pallet could be extended +to offer to the user claiming rewards for a project, a choice between more than one distribution pattern. + +The **Distribution Pallet** receives a list of Whitelisted/Nominated Projects with +their respective calculated rewards. For each project,it will create a corresponding +spending that will be stored until distribution time which corresponds to the beginning of an ***Epoch*** (The distribution timing can be configured to a different value in the runtime). + + +### Terminology + +- **PotId:** Pot containing the funds used to pay the rewards. +- **BufferPeriod:** minimum required buffer time period between project nomination and reward claim. +## Interface + +### Dispatchable Functions + +#### Public + +These calls can be made from any externally held account capable of creating +a signed extrinsic. + +Basic actions: +- `claim_reward_for` - From this extrinsic any user can claim a reward for a nominated/whitelisted project. +License: Apache-2.0 diff --git a/substrate/frame/distribution/src/lib.rs b/substrate/frame/distribution/src/lib.rs index c38467a20510..2d7a24a8d2f3 100644 --- a/substrate/frame/distribution/src/lib.rs +++ b/substrate/frame/distribution/src/lib.rs @@ -39,10 +39,10 @@ pub mod pallet { type RuntimeHoldReason: From; - /// This the minimum required time period between project whitelisting + /// This the minimum required buffer time period between project nomination /// and payment/reward_claim from the treasury. #[pallet::constant] - type PaymentPeriod: Get>; + type BufferPeriod: Get>; /// Maximum number projects that can be accepted by this pallet #[pallet::constant] diff --git a/substrate/frame/distribution/src/mock.rs b/substrate/frame/distribution/src/mock.rs index cd12617e764e..93bf5f231e15 100644 --- a/substrate/frame/distribution/src/mock.rs +++ b/substrate/frame/distribution/src/mock.rs @@ -81,7 +81,7 @@ impl pallet_distribution::Config for Test { type NativeBalance = Balances; type PotId = PotId; type RuntimeHoldReason = RuntimeHoldReason; - type PaymentPeriod = Period; + type BufferPeriod = Period; type MaxProjects = MaxProjects; type EpochDurationBlocks = EpochDurationBlocks; } diff --git a/substrate/frame/distribution/src/types.rs b/substrate/frame/distribution/src/types.rs index f6a5734afc98..13560e81f785 100644 --- a/substrate/frame/distribution/src/types.rs +++ b/substrate/frame/distribution/src/types.rs @@ -60,7 +60,7 @@ impl SpendingInfo { let claimed = false; let status = SpendingState::default(); let valid_from = - >::block_number().saturating_add(T::PaymentPeriod::get()); + >::block_number().saturating_add(T::BufferPeriod::get()); let spending = SpendingInfo { amount, valid_from, status, whitelisted_project, claimed }; diff --git a/substrate/frame/opf/src/functions.rs b/substrate/frame/opf/src/functions.rs index 35f08096e13c..9ec2e4b9dbd5 100644 --- a/substrate/frame/opf/src/functions.rs +++ b/substrate/frame/opf/src/functions.rs @@ -85,7 +85,7 @@ impl Pallet { // Send calculated reward for distribution let now = - >::block_number().checked_add(&T::PaymentPeriod::get()).ok_or(Error::::InvalidResult)?; + >::block_number().checked_add(&T::BufferPeriod::get()).ok_or(Error::::InvalidResult)?; let project_info = ProjectInfo { project_account: project, submission_block: now, @@ -131,7 +131,7 @@ impl Pallet { let _= Self::calculate_rewards(T::TemporaryRewards::get()).map_err(|_| Error::::FailedRewardCalculation); } - // Create a new round when we reach the end of the round. + // Create a new round when we reach the end of the current round. if (now % round_ending_block).is_zero(){ let _= VotingRoundInfo::::new(); }