inital commit, which is clearly not initial

Signed-off-by: Uncle Stretch <uncle.stretch@ghostchain.io>
This commit is contained in:
Uncle Stretch
2024-10-03 15:38:52 +03:00
commit 66719626bb
178 changed files with 41709 additions and 0 deletions

164
runtime/casper/src/cult/mod.rs Executable file
View File

@@ -0,0 +1,164 @@
use super::*;
use frame_support::{
parameter_types,
traits::{
EitherOf, EitherOfDiverse, MapSuccess, OriginTrait, TryWithMorphedArg,
tokens::pay::PayFromAccount,
},
};
use frame_system::EnsureRootWithSuccess;
use sp_core::{ConstU128, ConstU32};
use sp_runtime::traits::{ConstU16, TakeFirst};
use pallet_ranked_collective::EnsureOfRank;
use crate::{
// weights,
RuntimeCall, RuntimeEvent, Scheduler, DAYS, CSPR, AccountId, Balance,
TreasuryAccount, Balances, Preimage, Runtime,
};
mod origins;
pub use origins::{
pallet_cult_origins, Geniuses, Degens, Zombies, Skeletons, Ghosts,
EnsureCanRetainAt, EnsureCanPromoteTo, EnsureCult, ToVoice, CultTreasurySpender,
};
mod tracks;
pub use tracks::TracksInfo;
pub mod ranks {
use pallet_ranked_collective::Rank;
pub const LEVEL_1: Rank = 1;
pub const LEVEL_2: Rank = 2;
pub const LEVEL_3: Rank = 3;
pub const LEVEL_4: Rank = 4;
pub const LEVEL_5: Rank = 5;
}
impl pallet_cult_origins::Config for Runtime {}
parameter_types! {
pub const VoteLockingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1);
}
impl pallet_whitelist::Config for Runtime {
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WhitelistOrigin = EitherOfDiverse<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Skeletons,
>;
type DispatchWhitelistedOrigin = EitherOf<
EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
Geniuses,
>;
type Preimages = Preimage;
type WeightInfo = weights::pallet_whitelist::WeightInfo<Runtime>;
}
parameter_types! {
pub const AlarmInterval: BlockNumber = 1;
pub const UndecidingTimeout: BlockNumber = 7 * DAYS;
pub const SubmissionDeposit: Balance = CSPR;
}
pub type CultReferendaInstance = pallet_referenda::Instance1;
impl pallet_referenda::Config<CultReferendaInstance> for Runtime {
type WeightInfo = ();
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = Balances;
type SubmitOrigin = EitherOf<
pallet_ranked_collective::EnsureMember<Runtime, CultCollectiveInstance, 3>,
MapSuccess<
TryWithMorphedArg<
RuntimeOrigin,
<RuntimeOrigin as OriginTrait>::PalletsOrigin,
ToVoice,
EnsureOfRank<Runtime, CultCollectiveInstance>,
(AccountId, u16),
>,
TakeFirst,
>
>;
type CancelOrigin = Skeletons;
type KillOrigin = Ghosts;
type Slash = Treasury;
type Votes = pallet_ranked_collective::Votes;
type Tally = pallet_ranked_collective::TallyOf<Runtime, CultCollectiveInstance>;
type SubmissionDeposit = SubmissionDeposit;
type MaxQueued = ConstU32<100>;
type UndecidingTimeout = UndecidingTimeout;
type AlarmInterval = AlarmInterval;
type Tracks = TracksInfo;
type Preimages = Preimage;
}
pub type CultCollectiveInstance = pallet_ranked_collective::Instance1;
impl pallet_ranked_collective::Config<CultCollectiveInstance> for Runtime {
type WeightInfo = weights::pallet_ranked_collective::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
#[cfg(not(feature = "runtime-benchmarks"))]
type PromoteOrigin = frame_system::EnsureNever<pallet_ranked_collective::Rank>;
#[cfg(feature = "runtime-benchmarks")]
type PromoteOrigin = EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>;
#[cfg(not(feature = "runtime-benchmarks"))]
type AddOrigin = frame_system::EnsureNever<pallet_ranked_collective::Rank>;
#[cfg(feature = "runtime-benchmarks")]
type AddOrigin = EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>;
#[cfg(not(feature = "runtime-benchmarks"))]
type RemoveOrigin = frame_system::EnsureNever<pallet_ranked_collective::Rank>;
#[cfg(feature = "runtime-benchmarks")]
type RemoveOrigin = EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>;
type DemoteOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Ghosts>;
type ExchangeOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Ghosts>;
type Polls = CultReferenda;
type MinRankOfClass = tracks::MinRankOfClass;
type MemberSwappedHandler = (crate::CultCore, crate::CultSalary);
type VoteWeight = pallet_ranked_collective::Geometric;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkSetup = (crate::CultCore, crate::CultSalary);
}
pub type CultCoreInstance = pallet_core_fellowship::Instance1;
impl pallet_core_fellowship::Config<CultCoreInstance> for Runtime {
type WeightInfo = weights::pallet_core_fellowship::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type Members = pallet_ranked_collective::Pallet<Runtime, CultCollectiveInstance>;
type Balance = Balance;
type ParamsOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Skeletons>;
type InductOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Zombies>;
type ApproveOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, EnsureCanRetainAt>;
type PromoteOrigin = EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, EnsureCanPromoteTo>;
type EvidenceSize = ConstU32<65536>;
}
pub type CultSalaryInstance = pallet_salary::Instance1;
impl pallet_salary::Config<CultSalaryInstance> for Runtime {
type WeightInfo = weights::pallet_salary::WeightInfo<Runtime>;
type RuntimeEvent = RuntimeEvent;
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type Members = pallet_ranked_collective::Pallet<Runtime, CultCollectiveInstance>;
#[cfg(not(feature = "runtime-benchmarks"))]
type Salary = pallet_core_fellowship::Pallet<Runtime, CultCoreInstance>;
#[cfg(feature = "runtime-benchmarks")]
type Salary = frame_support::traits::tokens::ConvertRank<
crate::impls::benchmarks::RankToSalary<Balances>,
>;
type RegistrationPeriod = ConstU32<{ 15 * DAYS }>;
type PayoutPeriod = ConstU32<{ 15 * DAYS }>;
type Budget = ConstU128<{ 100 * CSPR }>;
}

View File

@@ -0,0 +1,168 @@
//! Custom origins for general governance interventions.
use super::ranks;
pub use pallet_cult_origins::*;
#[frame_support::pallet]
pub mod pallet_cult_origins {
use crate::{Balance, CSPR};
use super::ranks;
use frame_support::pallet_prelude::*;
use pallet_ranked_collective::Rank;
#[pallet::config]
pub trait Config: frame_system::Config {}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[derive(PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug)]
#[pallet::origin]
pub enum Origin {
Geniuses,
Degens,
Zombies,
Skeletons,
Ghosts,
RetainAt1Level,
RetainAt2Level,
RetainAt3Level,
RetainAt4Level,
RetainAt5Level,
PromoteTo1Level,
PromoteTo2Level,
PromoteTo3Level,
PromoteTo4Level,
PromoteTo5Level,
}
impl Origin {
pub fn as_voice(&self) -> Option<pallet_ranked_collective::Rank> {
Some(match &self {
Origin::Geniuses => ranks::LEVEL_1,
Origin::Degens => ranks::LEVEL_2,
Origin::Zombies => ranks::LEVEL_3,
Origin::Skeletons => ranks::LEVEL_4,
Origin::Ghosts => ranks::LEVEL_5,
_ => return None,
})
}
}
pub struct ToVoice;
impl<'a, O: 'a + TryInto<&'a Origin>> sp_runtime::traits::TryMorph<O> for ToVoice {
type Outcome = pallet_ranked_collective::Rank;
fn try_morph(o: O) -> Result<pallet_ranked_collective::Rank, ()> {
o.try_into().ok().and_then(Origin::as_voice).ok_or(())
}
}
macro_rules! decl_unit_ensures {
( $name:ident: $success_type:ty = $success:expr ) => {
pub struct $name;
impl<O: Into<Result<Origin, O>> + From<Origin>> EnsureOrigin<O> for $name {
type Success = $success_type;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
Origin::$name => Ok($success),
r => Err(O::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
Ok(O::from(Origin::$name))
}
}
};
( $name:ident ) => { decl_unit_ensures! { $name : () = () } };
( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => {
decl_unit_ensures! { $name: $success_type = $success }
decl_unit_ensures! { $( $rest )* }
};
( $name:ident, $( $rest:tt )* ) => {
decl_unit_ensures! { $name }
decl_unit_ensures! { $( $rest )* }
};
() => {}
}
decl_unit_ensures!(
Geniuses: Rank = ranks::LEVEL_1,
Degens: Rank = ranks::LEVEL_2,
Zombies: Rank = ranks::LEVEL_3,
Skeletons: Rank = ranks::LEVEL_4,
Ghosts: Rank = ranks::LEVEL_5,
);
macro_rules! decl_ensure {
(
$vis:vis type $name:ident: EnsureOrigin<Success = $success_type:ty> {
$( $item:ident = $success:expr, )*
}
) => {
$vis struct $name;
impl<O: Into<Result<Origin, O>> + From<Origin>> EnsureOrigin<O> for $name {
type Success = $success_type;
fn try_origin(o: O) -> Result<Self::Success, O> {
o.into().and_then(|o| match o {
$(
Origin::$item => Ok($success),
)*
r => Err(O::from(r)),
})
}
#[cfg(feature = "runtime-benchmarks")]
fn try_successful_origin() -> Result<O, ()> {
// By convention the more privileged origins go later,
// so for greatest chance of success, we want the last one.
let _result: Result<O, ()> = Err(());
$(
let _result: Result<O, ()> = Ok(O::from(Origin::$item));
)*
_result
}
}
}
}
decl_ensure! {
pub type EnsureCult: EnsureOrigin<Success = Rank> {
Geniuses = ranks::LEVEL_1,
Degens = ranks::LEVEL_2,
Zombies = ranks::LEVEL_3,
Skeletons = ranks::LEVEL_4,
Ghosts = ranks::LEVEL_5,
}
}
decl_ensure! {
pub type EnsureCanRetainAt: EnsureOrigin<Success = Rank> {
RetainAt1Level = ranks::LEVEL_1,
RetainAt2Level = ranks::LEVEL_2,
RetainAt3Level = ranks::LEVEL_3,
RetainAt4Level = ranks::LEVEL_4,
RetainAt5Level = ranks::LEVEL_5,
}
}
decl_ensure! {
pub type EnsureCanPromoteTo: EnsureOrigin<Success = Rank> {
PromoteTo1Level = ranks::LEVEL_1,
PromoteTo2Level = ranks::LEVEL_2,
PromoteTo3Level = ranks::LEVEL_3,
PromoteTo4Level = ranks::LEVEL_4,
PromoteTo5Level = ranks::LEVEL_5,
}
}
decl_ensure! {
pub type CultTreasurySpender: EnsureOrigin<Success = Balance> {
Geniuses = 50 * CSPR,
Degens = 100 * CSPR,
Zombies = 500 * CSPR,
Skeletons = 1_000 * CSPR,
Ghosts = 10_000 * CSPR,
}
}
}

377
runtime/casper/src/cult/tracks.rs Executable file
View File

@@ -0,0 +1,377 @@
use crate::{Balance, BlockNumber, RuntimeOrigin, DAYS, CSPR, HOURS, MINUTES};
use pallet_ranked_collective::Rank;
use sp_runtime::{traits::Convert, Perbill};
pub type TrackId = u16;
pub mod constants {
use super::TrackId;
pub const GENIUSES: TrackId = 1;
pub const DEGENS: TrackId = 2;
pub const ZOMBIES: TrackId = 3;
pub const SKELETONS: TrackId = 4;
pub const GHOSTS: TrackId = 5;
pub const RETAIN_AT_GENIUSES: TrackId = 10;
pub const RETAIN_AT_DEGENS: TrackId = 11;
pub const RETAIN_AT_ZOMBIES: TrackId = 12;
pub const RETAIN_AT_SKELETONS: TrackId = 13;
pub const RETAIN_AT_GHOSTS: TrackId = 14;
pub const PROMOTE_TO_GENIUSES: TrackId = 20;
pub const PROMOTE_TO_DEGENS: TrackId = 21;
pub const PROMOTE_TO_ZOMBIES: TrackId = 22;
pub const PROMOTE_TO_SKELETONS: TrackId = 23;
pub const PROMOTE_TO_GHOSTS: TrackId = 24;
}
/// Convert the track ID (defined above) into the minimum rank required.
pub struct MinRankOfClass;
impl Convert<TrackId, Rank> for MinRankOfClass {
fn convert(a: TrackId) -> Rank {
match a {
regular @ 1..=5 => regular,
retention @ 10..=13 => retention - 8,
promotion @ 20..=23 => promotion - 18,
14 | 24 => 5,
_ => Rank::MAX,
}
}
}
const RETAIN_MAX_DECIDING: u32 = 25;
const RETAIN_DECISION_DEPOSIT: Balance = 5 * CSPR;
const RETAIN_PREPARE_PERIOD: BlockNumber = 0;
const RETAIN_DECISION_PERIOD: BlockNumber = 14 * DAYS;
const RETAIN_CONFIRM_PERIOD: BlockNumber = HOURS;
const RETAIN_MIN_ENACTMENT_PERIOD: BlockNumber = 0;
const RETAIN_MIN_APPROVAL: pallet_referenda::Curve = pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(60),
ceil: Perbill::from_percent(100),
};
const RETAIN_MIN_SUPPORT: pallet_referenda::Curve = pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(10),
ceil: Perbill::from_percent(100),
};
const PROMOTE_MAX_DECIDING: u32 = 10;
const PROMOTE_DECISION_DEPOSIT: Balance = 5 * CSPR;
const PROMOTE_PREPARE_PERIOD: BlockNumber = 0;
const PROMOTE_DECISION_PERIOD: BlockNumber = 30 * DAYS;
const PROMOTE_CONFIRM_PERIOD: BlockNumber = HOURS;
const PROMOTE_MIN_ENACTMENT_PERIOD: BlockNumber = 0;
const PROMOTE_MIN_APPROVAL: pallet_referenda::Curve = pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(60),
ceil: Perbill::from_percent(100),
};
const PROMOTE_MIN_SUPPORT: pallet_referenda::Curve = pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(10),
ceil: Perbill::from_percent(100),
};
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15] = [
(
constants::GENIUSES,
pallet_referenda::TrackInfo {
name: "geniuses",
max_deciding: 10,
decision_deposit: 5 * CSPR,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
),
(
constants::DEGENS,
pallet_referenda::TrackInfo {
name: "degens",
max_deciding: 10,
decision_deposit: 5 * CSPR,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
),
(
constants::ZOMBIES,
pallet_referenda::TrackInfo {
name: "zombies",
max_deciding: 10,
decision_deposit: 5 * CSPR,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
),
(
constants::SKELETONS,
pallet_referenda::TrackInfo {
name: "skeletons",
max_deciding: 10,
decision_deposit: 5 * CSPR,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
),
(
constants::GHOSTS,
pallet_referenda::TrackInfo {
name: "skeletons",
max_deciding: 10,
decision_deposit: 5 * CSPR,
prepare_period: 30 * MINUTES,
decision_period: 7 * DAYS,
confirm_period: 30 * MINUTES,
min_enactment_period: 5 * MINUTES,
min_approval: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(50),
ceil: Perbill::from_percent(100),
},
min_support: pallet_referenda::Curve::LinearDecreasing {
length: Perbill::from_percent(100),
floor: Perbill::from_percent(0),
ceil: Perbill::from_percent(100),
},
},
),
(
constants::RETAIN_AT_GENIUSES,
pallet_referenda::TrackInfo {
name: "retain a genius",
max_deciding: RETAIN_MAX_DECIDING,
decision_deposit: RETAIN_DECISION_DEPOSIT,
prepare_period: RETAIN_PREPARE_PERIOD,
decision_period: RETAIN_DECISION_PERIOD,
confirm_period: RETAIN_CONFIRM_PERIOD,
min_enactment_period: RETAIN_MIN_ENACTMENT_PERIOD,
min_approval: RETAIN_MIN_APPROVAL,
min_support: RETAIN_MIN_SUPPORT,
},
),
(
constants::RETAIN_AT_DEGENS,
pallet_referenda::TrackInfo {
name: "retain a degen",
max_deciding: RETAIN_MAX_DECIDING,
decision_deposit: RETAIN_DECISION_DEPOSIT,
prepare_period: RETAIN_PREPARE_PERIOD,
decision_period: RETAIN_DECISION_PERIOD,
confirm_period: RETAIN_CONFIRM_PERIOD,
min_enactment_period: RETAIN_MIN_ENACTMENT_PERIOD,
min_approval: RETAIN_MIN_APPROVAL,
min_support: RETAIN_MIN_SUPPORT,
},
),
(
constants::RETAIN_AT_ZOMBIES,
pallet_referenda::TrackInfo {
name: "retain a zombie",
max_deciding: RETAIN_MAX_DECIDING,
decision_deposit: RETAIN_DECISION_DEPOSIT,
prepare_period: RETAIN_PREPARE_PERIOD,
decision_period: RETAIN_DECISION_PERIOD,
confirm_period: RETAIN_CONFIRM_PERIOD,
min_enactment_period: RETAIN_MIN_ENACTMENT_PERIOD,
min_approval: RETAIN_MIN_APPROVAL,
min_support: RETAIN_MIN_SUPPORT,
},
),
(
constants::RETAIN_AT_SKELETONS,
pallet_referenda::TrackInfo {
name: "retain a skeleton",
max_deciding: RETAIN_MAX_DECIDING,
decision_deposit: RETAIN_DECISION_DEPOSIT,
prepare_period: RETAIN_PREPARE_PERIOD,
decision_period: RETAIN_DECISION_PERIOD,
confirm_period: RETAIN_CONFIRM_PERIOD,
min_enactment_period: RETAIN_MIN_ENACTMENT_PERIOD,
min_approval: RETAIN_MIN_APPROVAL,
min_support: RETAIN_MIN_SUPPORT,
},
),
(
constants::RETAIN_AT_GHOSTS,
pallet_referenda::TrackInfo {
name: "retain a ghost",
max_deciding: RETAIN_MAX_DECIDING,
decision_deposit: RETAIN_DECISION_DEPOSIT,
prepare_period: RETAIN_PREPARE_PERIOD,
decision_period: RETAIN_DECISION_PERIOD,
confirm_period: RETAIN_CONFIRM_PERIOD,
min_enactment_period: RETAIN_MIN_ENACTMENT_PERIOD,
min_approval: RETAIN_MIN_APPROVAL,
min_support: RETAIN_MIN_SUPPORT,
},
),
(
constants::PROMOTE_TO_GENIUSES,
pallet_referenda::TrackInfo {
name: "promote to genius",
max_deciding: PROMOTE_MAX_DECIDING,
decision_deposit: PROMOTE_DECISION_DEPOSIT,
prepare_period: PROMOTE_PREPARE_PERIOD,
decision_period: PROMOTE_DECISION_PERIOD,
confirm_period: PROMOTE_CONFIRM_PERIOD,
min_enactment_period: PROMOTE_MIN_ENACTMENT_PERIOD,
min_approval: PROMOTE_MIN_APPROVAL,
min_support: PROMOTE_MIN_SUPPORT,
},
),
(
constants::PROMOTE_TO_DEGENS,
pallet_referenda::TrackInfo {
name: "promote to degen",
max_deciding: PROMOTE_MAX_DECIDING,
decision_deposit: PROMOTE_DECISION_DEPOSIT,
prepare_period: PROMOTE_PREPARE_PERIOD,
decision_period: PROMOTE_DECISION_PERIOD,
confirm_period: PROMOTE_CONFIRM_PERIOD,
min_enactment_period: PROMOTE_MIN_ENACTMENT_PERIOD,
min_approval: PROMOTE_MIN_APPROVAL,
min_support: PROMOTE_MIN_SUPPORT,
},
),
(
constants::PROMOTE_TO_ZOMBIES,
pallet_referenda::TrackInfo {
name: "promote to zombie",
max_deciding: PROMOTE_MAX_DECIDING,
decision_deposit: PROMOTE_DECISION_DEPOSIT,
prepare_period: PROMOTE_PREPARE_PERIOD,
decision_period: PROMOTE_DECISION_PERIOD,
confirm_period: PROMOTE_CONFIRM_PERIOD,
min_enactment_period: PROMOTE_MIN_ENACTMENT_PERIOD,
min_approval: PROMOTE_MIN_APPROVAL,
min_support: PROMOTE_MIN_SUPPORT,
},
),
(
constants::PROMOTE_TO_SKELETONS,
pallet_referenda::TrackInfo {
name: "promote to skeleton",
max_deciding: PROMOTE_MAX_DECIDING,
decision_deposit: PROMOTE_DECISION_DEPOSIT,
prepare_period: PROMOTE_PREPARE_PERIOD,
decision_period: PROMOTE_DECISION_PERIOD,
confirm_period: PROMOTE_CONFIRM_PERIOD,
min_enactment_period: PROMOTE_MIN_ENACTMENT_PERIOD,
min_approval: PROMOTE_MIN_APPROVAL,
min_support: PROMOTE_MIN_SUPPORT,
},
),
(
constants::PROMOTE_TO_GHOSTS,
pallet_referenda::TrackInfo {
name: "promote to ghost",
max_deciding: PROMOTE_MAX_DECIDING,
decision_deposit: PROMOTE_DECISION_DEPOSIT,
prepare_period: PROMOTE_PREPARE_PERIOD,
decision_period: PROMOTE_DECISION_PERIOD,
confirm_period: PROMOTE_CONFIRM_PERIOD,
min_enactment_period: PROMOTE_MIN_ENACTMENT_PERIOD,
min_approval: PROMOTE_MIN_APPROVAL,
min_support: PROMOTE_MIN_SUPPORT,
},
),
];
pub struct TracksInfo;
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
type Id = TrackId;
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
&TRACKS_DATA[..]
}
fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
use super::origins::Origin;
use constants as tracks;
#[cfg(feature = "runtime-benchmarks")]
{
// For benchmark we enable root origin.
// It is important that this is NOT availiable in production!
let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
if &root == id {
return Ok(tracks::GHOSTS)
}
}
match Origin::try_from(id.clone()) {
Ok(Origin::Geniuses) => Ok(tracks::GENIUSES),
Ok(Origin::Degens) => Ok(tracks::DEGENS),
Ok(Origin::Zombies) => Ok(tracks::ZOMBIES),
Ok(Origin::Skeletons) => Ok(tracks::SKELETONS),
Ok(Origin::Ghosts) => Ok(tracks::GHOSTS),
Ok(Origin::RetainAt1Level) => Ok(tracks::RETAIN_AT_GENIUSES),
Ok(Origin::RetainAt2Level) => Ok(tracks::RETAIN_AT_DEGENS),
Ok(Origin::RetainAt3Level) => Ok(tracks::RETAIN_AT_ZOMBIES),
Ok(Origin::RetainAt4Level) => Ok(tracks::RETAIN_AT_SKELETONS),
Ok(Origin::RetainAt5Level) => Ok(tracks::RETAIN_AT_GHOSTS),
Ok(Origin::PromoteTo1Level) => Ok(tracks::PROMOTE_TO_GENIUSES),
Ok(Origin::PromoteTo2Level) => Ok(tracks::PROMOTE_TO_GENIUSES),
Ok(Origin::PromoteTo3Level) => Ok(tracks::PROMOTE_TO_ZOMBIES),
Ok(Origin::PromoteTo4Level) => Ok(tracks::PROMOTE_TO_SKELETONS),
Ok(Origin::PromoteTo5Level) => Ok(tracks::PROMOTE_TO_GHOSTS),
_ => Err(()),
}
}
}
pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);