Skip to content

Commit

Permalink
New OPF pallet in work...
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkazu committed Dec 24, 2024
1 parent 0a41d8f commit 859e6b3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 19 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions substrate/frame/opf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ frame-support = { workspace = true, default-features = false }
frame-system = { workspace = true, default-features = false }
log = { workspace = true }
pallet-conviction-voting = { workspace = true, default-features = false }
pallet-scheduler = { workspace = true, default-features = false }
scale-info = { features = [
"derive",
], workspace = true, default-features = false }
serde = { optional = true, workspace = true, default-features = true }
sp-core = { workspace = true, default-features = false }
sp-io = { workspace = true, default-features = false }
sp-runtime = { workspace = true, default-features = false }
sp-std = { workspace = true, default-features = true }

[dev-dependencies]
pallet-assets = { workspace = true, default-features = true }
Expand All @@ -53,6 +56,8 @@ runtime-benchmarks = [
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks",
"scale-info/std",
"serde",
"sp-runtime/runtime-benchmarks",
]
std = [
Expand Down
57 changes: 43 additions & 14 deletions substrate/frame/opf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
mod functions;
mod types;
pub use pallet_scheduler as Schedule;
pub use types::*;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;

#[cfg(test)]
mod mock;

#[cfg(test)]
mod tests;
pub mod weights;

#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_system::WeightInfo;

#[pallet::pallet]
pub struct Pallet<T>(_);
Expand All @@ -35,11 +27,7 @@ pub mod pallet {

/// Type to access the Balances Pallet.
type NativeBalance: fungible::Inspect<Self::AccountId>
+ fungible::Mutate<Self::AccountId>
+ fungible::hold::Inspect<Self::AccountId>
+ fungible::hold::Mutate<Self::AccountId, Reason = Self::RuntimeHoldReason>
+ fungible::freeze::Inspect<Self::AccountId>
+ fungible::freeze::Mutate<Self::AccountId>;
+ fungible::Mutate<Self::AccountId>;

/// Provider for the block number.
type BlockNumberProvider: BlockNumberProvider<BlockNumber = BlockNumberFor<Self>>;
Expand Down Expand Up @@ -89,6 +77,15 @@ pub mod pallet {
type WeightInfo: WeightInfo;
}

/// Number of Voting Rounds executed so far
#[pallet::storage]
pub type VotingRoundNumber<T: Config> = StorageValue<_, u32, ValueQuery>;

/// Returns Infos about a Voting Round agains the Voting Round index
#[pallet::storage]
pub type VotingRounds<T: Config> =
StorageMap<_, Twox64Concat, RoundIndex, VotingRoundInfo<T>, OptionQuery>;

/// Spends that still have to be claimed.
#[pallet::storage]
pub(super) type Spends<T: Config> =
Expand All @@ -113,6 +110,38 @@ pub mod pallet {

/// Payment will be enacted for corresponding project
WillBeEnacted { project_id: ProjectId<T> },

/// Reward successfully assigned
RewardsAssigned { when: BlockNumberFor<T> },

/// User's vote successfully submitted
VoteCasted { who: VoterId<T>, when: BlockNumberFor<T>, project_id: ProjectId<T> },

/// User's vote successfully removed
VoteRemoved { who: VoterId<T>, when: BlockNumberFor<T>, project_id: ProjectId<T> },

/// Project removed from whitelisted projects list
ProjectUnlisted { when: BlockNumberFor<T>, project_id: ProjectId<T> },

/// Project Funding Accepted by voters
ProjectFundingAccepted {
project_id: ProjectId<T>,
when: BlockNumberFor<T>,
round_number: u32,
amount: BalanceOf<T>,
},

/// Project Funding rejected by voters
ProjectFundingRejected { when: BlockNumberFor<T>, project_id: ProjectId<T> },

/// A new voting round started
VotingRoundStarted { when: BlockNumberFor<T>, round_number: u32 },

/// The users voting period ended. Reward calculation will start.
VoteActionLocked { when: BlockNumberFor<T>, round_number: u32 },

/// The voting round ended
VotingRoundEnded { when: BlockNumberFor<T>, round_number: u32 },
}

#[pallet::error]
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/opf/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ pub use frame_support::{
},
transactional, PalletId, Serialize,
};
pub use pallet_conviction_voting::Conviction;
pub use frame_system::{pallet_prelude::*, RawOrigin};
pub use scale_info::prelude::vec::Vec;
pub use sp_runtime::traits::{
AccountIdConversion, BlockNumberProvider, Convert, Dispatchable, Saturating, StaticLookup, Zero,
};
pub use sp_std::boxed::Box;
pub use weights::WeightInfo;

pub type BalanceOf<T> = <<T as Config>::NativeBalance as fungible::Inspect<
<T as frame_system::Config>::AccountId,
Expand All @@ -55,7 +55,7 @@ pub type ProjectId<T> = AccountIdOf<T>;
pub type PalletsOriginOf<T> =
<<T as frame_system::Config>::RuntimeOrigin as OriginTrait>::PalletsOrigin;
pub const DISTRIBUTION_ID: LockIdentifier = *b"distribu";
ub type RoundIndex = u32;
pub type RoundIndex = u32;
pub type VoterId<T> = AccountIdOf<T>;

/// The state of the payment claim.
Expand Down Expand Up @@ -93,7 +93,7 @@ impl<T: Config> SpendInfo<T> {
let claimed = false;
let valid_from =
<frame_system::Pallet<T>>::block_number();
let expire = valid_from.clone().saturating_add(T::ClaimingPeriod::get())
let expire = valid_from.clone().saturating_add(T::ClaimingPeriod::get());

let spend = SpendInfo { amount, valid_from, whitelisted_project, claimed, expire };

Expand Down Expand Up @@ -140,8 +140,7 @@ impl<T: Config> VoteInfo<T> {
let conviction_coeff = <u8 as From<Conviction>>::from(self.conviction);

Check failure on line 140 in substrate/frame/opf/src/types.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

unused variable: `conviction_coeff`
let funds_unlock_block = self
.round
.round_ending_block
.saturating_add(T::VoteLockingPeriod::get().saturating_mul(conviction_coeff.into()));
.round_ending_block;
self.funds_unlock_block = funds_unlock_block;
}
}
Expand Down
5 changes: 5 additions & 0 deletions umbrella/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,11 @@ pub use pallet_offences;
#[cfg(feature = "pallet-offences-benchmarking")]
pub use pallet_offences_benchmarking;

/// Optimist Project Funding - pallet allowing users to nominate projects to be funded, by
/// locking their DOTS.
#[cfg(feature = "pallet-opf")]
pub use pallet_opf;

/// FRAME pallet that provides a paged list data structure.
#[cfg(feature = "pallet-paged-list")]
pub use pallet_paged_list;
Expand Down

0 comments on commit 859e6b3

Please sign in to comment.