Skip to content

Commit

Permalink
Distribution pallet README
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Aug 5, 2024
1 parent 843f558 commit b69cfff
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion substrate/bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions substrate/frame/distribution/README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions substrate/frame/distribution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub mod pallet {

type RuntimeHoldReason: From<HoldReason>;

/// 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<BlockNumberFor<Self>>;
type BufferPeriod: Get<BlockNumberFor<Self>>;

/// Maximum number projects that can be accepted by this pallet
#[pallet::constant]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/distribution/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/distribution/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<T: Config> SpendingInfo<T> {
let claimed = false;
let status = SpendingState::default();
let valid_from =
<frame_system::Pallet<T>>::block_number().saturating_add(T::PaymentPeriod::get());
<frame_system::Pallet<T>>::block_number().saturating_add(T::BufferPeriod::get());

let spending = SpendingInfo { amount, valid_from, status, whitelisted_project, claimed };

Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/opf/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<T: Config> Pallet<T> {

// Send calculated reward for distribution
let now =
<frame_system::Pallet<T>>::block_number().checked_add(&T::PaymentPeriod::get()).ok_or(Error::<T>::InvalidResult)?;
<frame_system::Pallet<T>>::block_number().checked_add(&T::BufferPeriod::get()).ok_or(Error::<T>::InvalidResult)?;
let project_info = ProjectInfo {
project_account: project,
submission_block: now,
Expand Down Expand Up @@ -131,7 +131,7 @@ impl<T: Config> Pallet<T> {
let _= Self::calculate_rewards(T::TemporaryRewards::get()).map_err(|_| Error::<T>::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::<T>::new();
}
Expand Down

0 comments on commit b69cfff

Please sign in to comment.