mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-01 02:11:01 +00:00
OpenGov in Westend and Rococo (#1177)
Migrating [PR from the archived polkadot repo](https://github.com/paritytech/polkadot/pull/7272) As per https://github.com/paritytech/polkadot/pull/7272#issuecomment-1559240466, the changes in this MR include the following pallets into [x] Rococo and [x] Westend runtimes: pallet_conviction_voting pallet_referenda pallet_ranked_collective pallet_custom_origins pallet_whitelist And only for westend-runtime: pallet_treasury Following [Kusama runtime config](https://github.com/paritytech/polkadot/tree/dbae30efe080a1d41fe54ef4da8af47614c9ca93/runtime/kusama/src) as a baseline. Benchmarking of the following pallets done for both Rococo and Westend: pallet_conviction_voting pallet_referenda pallet_ranked_collective (only on Rococo) pallet_whitelist And only for Westend: pallet_treasury Removed Gov1 from Rococo as in https://github.com/paritytech/polkadot/pull/6701 Rococo Gov1 storage will be cleaned in a different PR - [issue ](https://github.com/paritytech/polkadot-sdk/issues/1618) --------- Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
committed by
GitHub
parent
8b061a5c5d
commit
69ed3087e1
@@ -0,0 +1,343 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Elements of governance concerning the Rococo Fellowship.
|
||||
|
||||
use frame_support::traits::{MapSuccess, TryMapSuccess};
|
||||
use sp_runtime::traits::{CheckedReduceBy, ConstU16, Replace};
|
||||
|
||||
use super::*;
|
||||
use crate::{CENTS, DAYS};
|
||||
|
||||
parameter_types! {
|
||||
pub const AlarmInterval: BlockNumber = 1;
|
||||
pub const SubmissionDeposit: Balance = 0;
|
||||
pub const UndecidingTimeout: BlockNumber = 7 * DAYS;
|
||||
}
|
||||
|
||||
pub struct TracksInfo;
|
||||
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
|
||||
type Id = u16;
|
||||
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
|
||||
fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo<Balance, BlockNumber>)] {
|
||||
static DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 10] = [
|
||||
(
|
||||
0u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "candidates",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 100 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
1u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "members",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 10 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
2u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "proficients",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 10 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
3u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "fellows",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 10 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
4u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "senior fellows",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 10 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
5u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "experts",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 1 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
6u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "senior experts",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 1 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
7u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "masters",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 1 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
8u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "senior masters",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 1 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
(
|
||||
9u16,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "grand masters",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 1 * 3 * CENTS,
|
||||
prepare_period: 30 * MINUTES,
|
||||
decision_period: 7 * DAYS,
|
||||
confirm_period: 30 * MINUTES,
|
||||
min_enactment_period: 1 * 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(50),
|
||||
},
|
||||
},
|
||||
),
|
||||
];
|
||||
&DATA[..]
|
||||
}
|
||||
fn track_for(id: &Self::RuntimeOrigin) -> Result<Self::Id, ()> {
|
||||
use super::origins::Origin;
|
||||
|
||||
#[cfg(feature = "runtime-benchmarks")]
|
||||
{
|
||||
// For benchmarks, we enable a root origin.
|
||||
// It is important that this is not available in production!
|
||||
let root: Self::RuntimeOrigin = frame_system::RawOrigin::Root.into();
|
||||
if &root == id {
|
||||
return Ok(9)
|
||||
}
|
||||
}
|
||||
|
||||
match Origin::try_from(id.clone()) {
|
||||
Ok(Origin::FellowshipInitiates) => Ok(0),
|
||||
Ok(Origin::Fellowship1Dan) => Ok(1),
|
||||
Ok(Origin::Fellowship2Dan) => Ok(2),
|
||||
Ok(Origin::Fellowship3Dan) | Ok(Origin::Fellows) => Ok(3),
|
||||
Ok(Origin::Fellowship4Dan) => Ok(4),
|
||||
Ok(Origin::Fellowship5Dan) | Ok(Origin::FellowshipExperts) => Ok(5),
|
||||
Ok(Origin::Fellowship6Dan) => Ok(6),
|
||||
Ok(Origin::Fellowship7Dan | Origin::FellowshipMasters) => Ok(7),
|
||||
Ok(Origin::Fellowship8Dan) => Ok(8),
|
||||
Ok(Origin::Fellowship9Dan) => Ok(9),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
|
||||
|
||||
pub type FellowshipReferendaInstance = pallet_referenda::Instance2;
|
||||
|
||||
impl pallet_referenda::Config<FellowshipReferendaInstance> for Runtime {
|
||||
type WeightInfo = weights::pallet_referenda_fellowship_referenda::WeightInfo<Self>;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Scheduler = Scheduler;
|
||||
type Currency = Balances;
|
||||
type SubmitOrigin =
|
||||
pallet_ranked_collective::EnsureMember<Runtime, FellowshipCollectiveInstance, 1>;
|
||||
type CancelOrigin = FellowshipExperts;
|
||||
type KillOrigin = FellowshipMasters;
|
||||
type Slash = Treasury;
|
||||
type Votes = pallet_ranked_collective::Votes;
|
||||
type Tally = pallet_ranked_collective::TallyOf<Runtime, FellowshipCollectiveInstance>;
|
||||
type SubmissionDeposit = SubmissionDeposit;
|
||||
type MaxQueued = ConstU32<100>;
|
||||
type UndecidingTimeout = UndecidingTimeout;
|
||||
type AlarmInterval = AlarmInterval;
|
||||
type Tracks = TracksInfo;
|
||||
type Preimages = Preimage;
|
||||
}
|
||||
|
||||
pub type FellowshipCollectiveInstance = pallet_ranked_collective::Instance1;
|
||||
|
||||
impl pallet_ranked_collective::Config<FellowshipCollectiveInstance> for Runtime {
|
||||
type WeightInfo = weights::pallet_ranked_collective::WeightInfo<Self>;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
// Promotion is by any of:
|
||||
// - Root can demote arbitrarily.
|
||||
// - the FellowshipAdmin origin (i.e. token holder referendum);
|
||||
// - a vote by the rank *above* the new rank.
|
||||
type PromoteOrigin = EitherOf<
|
||||
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
||||
EitherOf<
|
||||
MapSuccess<FellowshipAdmin, Replace<ConstU16<9>>>,
|
||||
TryMapSuccess<origins::EnsureFellowship, CheckedReduceBy<ConstU16<1>>>,
|
||||
>,
|
||||
>;
|
||||
// Demotion is by any of:
|
||||
// - Root can demote arbitrarily.
|
||||
// - the FellowshipAdmin origin (i.e. token holder referendum);
|
||||
// - a vote by the rank two above the current rank.
|
||||
type DemoteOrigin = EitherOf<
|
||||
frame_system::EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>,
|
||||
EitherOf<
|
||||
MapSuccess<FellowshipAdmin, Replace<ConstU16<9>>>,
|
||||
TryMapSuccess<origins::EnsureFellowship, CheckedReduceBy<ConstU16<2>>>,
|
||||
>,
|
||||
>;
|
||||
type Polls = FellowshipReferenda;
|
||||
type MinRankOfClass = sp_runtime::traits::Identity;
|
||||
type VoteWeight = pallet_ranked_collective::Geometric;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! New governance configurations for the Rococo runtime.
|
||||
|
||||
use super::*;
|
||||
use frame_support::{
|
||||
parameter_types,
|
||||
traits::{ConstU16, EitherOf},
|
||||
};
|
||||
use frame_system::EnsureRootWithSuccess;
|
||||
|
||||
mod origins;
|
||||
pub use origins::{
|
||||
pallet_custom_origins, AuctionAdmin, Fellows, FellowshipAdmin, FellowshipExperts,
|
||||
FellowshipInitiates, FellowshipMasters, GeneralAdmin, LeaseAdmin, ReferendumCanceller,
|
||||
ReferendumKiller, Spender, StakingAdmin, Treasurer, WhitelistedCaller,
|
||||
};
|
||||
mod tracks;
|
||||
pub use tracks::TracksInfo;
|
||||
mod fellowship;
|
||||
pub use fellowship::{FellowshipCollectiveInstance, FellowshipReferendaInstance};
|
||||
|
||||
parameter_types! {
|
||||
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
|
||||
}
|
||||
|
||||
impl pallet_conviction_voting::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_conviction_voting::WeightInfo<Self>;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Currency = Balances;
|
||||
type VoteLockingPeriod = VoteLockingPeriod;
|
||||
type MaxVotes = ConstU32<512>;
|
||||
type MaxTurnout =
|
||||
frame_support::traits::tokens::currency::ActiveIssuanceOf<Balances, Self::AccountId>;
|
||||
type Polls = Referenda;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const AlarmInterval: BlockNumber = 1;
|
||||
pub const SubmissionDeposit: Balance = 1 * 3 * CENTS;
|
||||
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MaxBalance: Balance = Balance::max_value();
|
||||
}
|
||||
pub type TreasurySpender = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, Spender>;
|
||||
|
||||
impl origins::pallet_custom_origins::Config for Runtime {}
|
||||
|
||||
impl pallet_whitelist::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_whitelist::WeightInfo<Self>;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type WhitelistOrigin =
|
||||
EitherOf<EnsureRootWithSuccess<Self::AccountId, ConstU16<65535>>, Fellows>;
|
||||
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
|
||||
type Preimages = Preimage;
|
||||
}
|
||||
|
||||
impl pallet_referenda::Config for Runtime {
|
||||
type WeightInfo = weights::pallet_referenda_referenda::WeightInfo<Self>;
|
||||
type RuntimeCall = RuntimeCall;
|
||||
type RuntimeEvent = RuntimeEvent;
|
||||
type Scheduler = Scheduler;
|
||||
type Currency = Balances;
|
||||
type SubmitOrigin = frame_system::EnsureSigned<AccountId>;
|
||||
type CancelOrigin = EitherOf<EnsureRoot<AccountId>, ReferendumCanceller>;
|
||||
type KillOrigin = EitherOf<EnsureRoot<AccountId>, ReferendumKiller>;
|
||||
type Slash = Treasury;
|
||||
type Votes = pallet_conviction_voting::VotesOf<Runtime>;
|
||||
type Tally = pallet_conviction_voting::TallyOf<Runtime>;
|
||||
type SubmissionDeposit = SubmissionDeposit;
|
||||
type MaxQueued = ConstU32<100>;
|
||||
type UndecidingTimeout = UndecidingTimeout;
|
||||
type AlarmInterval = AlarmInterval;
|
||||
type Tracks = TracksInfo;
|
||||
type Preimages = Preimage;
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Custom origins for governance interventions.
|
||||
|
||||
pub use pallet_custom_origins::*;
|
||||
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet_custom_origins {
|
||||
use crate::{Balance, CENTS, GRAND};
|
||||
use frame_support::pallet_prelude::*;
|
||||
|
||||
#[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 {
|
||||
/// Origin for cancelling slashes.
|
||||
StakingAdmin,
|
||||
/// Origin for spending (any amount of) funds.
|
||||
Treasurer,
|
||||
/// Origin for managing the composition of the fellowship.
|
||||
FellowshipAdmin,
|
||||
/// Origin for managing the registrar.
|
||||
GeneralAdmin,
|
||||
/// Origin for starting auctions.
|
||||
AuctionAdmin,
|
||||
/// Origin able to force slot leases.
|
||||
LeaseAdmin,
|
||||
/// Origin able to cancel referenda.
|
||||
ReferendumCanceller,
|
||||
/// Origin able to kill referenda.
|
||||
ReferendumKiller,
|
||||
/// Origin able to spend up to 1 KSM from the treasury at once.
|
||||
SmallTipper,
|
||||
/// Origin able to spend up to 5 KSM from the treasury at once.
|
||||
BigTipper,
|
||||
/// Origin able to spend up to 50 KSM from the treasury at once.
|
||||
SmallSpender,
|
||||
/// Origin able to spend up to 500 KSM from the treasury at once.
|
||||
MediumSpender,
|
||||
/// Origin able to spend up to 5,000 KSM from the treasury at once.
|
||||
BigSpender,
|
||||
/// Origin able to dispatch a whitelisted call.
|
||||
WhitelistedCaller,
|
||||
/// Origin commanded by any members of the Polkadot Fellowship (no Dan grade needed).
|
||||
FellowshipInitiates,
|
||||
/// Origin commanded by Polkadot Fellows (3rd Dan fellows or greater).
|
||||
Fellows,
|
||||
/// Origin commanded by Polkadot Experts (5th Dan fellows or greater).
|
||||
FellowshipExperts,
|
||||
/// Origin commanded by Polkadot Masters (7th Dan fellows of greater).
|
||||
FellowshipMasters,
|
||||
/// Origin commanded by rank 1 of the Polkadot Fellowship and with a success of 1.
|
||||
Fellowship1Dan,
|
||||
/// Origin commanded by rank 2 of the Polkadot Fellowship and with a success of 2.
|
||||
Fellowship2Dan,
|
||||
/// Origin commanded by rank 3 of the Polkadot Fellowship and with a success of 3.
|
||||
Fellowship3Dan,
|
||||
/// Origin commanded by rank 4 of the Polkadot Fellowship and with a success of 4.
|
||||
Fellowship4Dan,
|
||||
/// Origin commanded by rank 5 of the Polkadot Fellowship and with a success of 5.
|
||||
Fellowship5Dan,
|
||||
/// Origin commanded by rank 6 of the Polkadot Fellowship and with a success of 6.
|
||||
Fellowship6Dan,
|
||||
/// Origin commanded by rank 7 of the Polkadot Fellowship and with a success of 7.
|
||||
Fellowship7Dan,
|
||||
/// Origin commanded by rank 8 of the Polkadot Fellowship and with a success of 8.
|
||||
Fellowship8Dan,
|
||||
/// Origin commanded by rank 9 of the Polkadot Fellowship and with a success of 9.
|
||||
Fellowship9Dan,
|
||||
}
|
||||
|
||||
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!(
|
||||
StakingAdmin,
|
||||
Treasurer,
|
||||
FellowshipAdmin,
|
||||
GeneralAdmin,
|
||||
AuctionAdmin,
|
||||
LeaseAdmin,
|
||||
ReferendumCanceller,
|
||||
ReferendumKiller,
|
||||
WhitelistedCaller,
|
||||
FellowshipInitiates: u16 = 0,
|
||||
Fellows: u16 = 3,
|
||||
FellowshipExperts: u16 = 5,
|
||||
FellowshipMasters: u16 = 7,
|
||||
);
|
||||
|
||||
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 Spender: EnsureOrigin<Success = Balance> {
|
||||
SmallTipper = 250 * 3 * CENTS,
|
||||
BigTipper = 1 * GRAND,
|
||||
SmallSpender = 10 * GRAND,
|
||||
MediumSpender = 100 * GRAND,
|
||||
BigSpender = 1_000 * GRAND,
|
||||
Treasurer = 10_000 * GRAND,
|
||||
}
|
||||
}
|
||||
|
||||
decl_ensure! {
|
||||
pub type EnsureFellowship: EnsureOrigin<Success = u16> {
|
||||
Fellowship1Dan = 1,
|
||||
Fellowship2Dan = 2,
|
||||
Fellowship3Dan = 3,
|
||||
Fellowship4Dan = 4,
|
||||
Fellowship5Dan = 5,
|
||||
Fellowship6Dan = 6,
|
||||
Fellowship7Dan = 7,
|
||||
Fellowship8Dan = 8,
|
||||
Fellowship9Dan = 9,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
// Copyright (C) Parity Technologies (UK) Ltd.
|
||||
// This file is part of Polkadot.
|
||||
|
||||
// Polkadot is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Polkadot is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Track configurations for governance.
|
||||
|
||||
use super::*;
|
||||
|
||||
const fn percent(x: i32) -> sp_arithmetic::FixedI64 {
|
||||
sp_arithmetic::FixedI64::from_rational(x as u128, 100)
|
||||
}
|
||||
use pallet_referenda::Curve;
|
||||
const APP_ROOT: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
|
||||
const SUP_ROOT: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
|
||||
const APP_STAKING_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_STAKING_ADMIN: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_TREASURER: Curve = Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
|
||||
const SUP_TREASURER: Curve = Curve::make_linear(28, 28, percent(0), percent(50));
|
||||
const APP_FELLOWSHIP_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_FELLOWSHIP_ADMIN: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_GENERAL_ADMIN: Curve =
|
||||
Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
|
||||
const SUP_GENERAL_ADMIN: Curve =
|
||||
Curve::make_reciprocal(7, 28, percent(10), percent(0), percent(50));
|
||||
const APP_AUCTION_ADMIN: Curve =
|
||||
Curve::make_reciprocal(4, 28, percent(80), percent(50), percent(100));
|
||||
const SUP_AUCTION_ADMIN: Curve =
|
||||
Curve::make_reciprocal(7, 28, percent(10), percent(0), percent(50));
|
||||
const APP_LEASE_ADMIN: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_LEASE_ADMIN: Curve = Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_REFERENDUM_CANCELLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_REFERENDUM_CANCELLER: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_REFERENDUM_KILLER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_REFERENDUM_KILLER: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_SMALL_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
|
||||
const SUP_SMALL_TIPPER: Curve = Curve::make_reciprocal(1, 28, percent(4), percent(0), percent(50));
|
||||
const APP_BIG_TIPPER: Curve = Curve::make_linear(10, 28, percent(50), percent(100));
|
||||
const SUP_BIG_TIPPER: Curve = Curve::make_reciprocal(8, 28, percent(1), percent(0), percent(50));
|
||||
const APP_SMALL_SPENDER: Curve = Curve::make_linear(17, 28, percent(50), percent(100));
|
||||
const SUP_SMALL_SPENDER: Curve =
|
||||
Curve::make_reciprocal(12, 28, percent(1), percent(0), percent(50));
|
||||
const APP_MEDIUM_SPENDER: Curve = Curve::make_linear(23, 28, percent(50), percent(100));
|
||||
const SUP_MEDIUM_SPENDER: Curve =
|
||||
Curve::make_reciprocal(16, 28, percent(1), percent(0), percent(50));
|
||||
const APP_BIG_SPENDER: Curve = Curve::make_linear(28, 28, percent(50), percent(100));
|
||||
const SUP_BIG_SPENDER: Curve = Curve::make_reciprocal(20, 28, percent(1), percent(0), percent(50));
|
||||
const APP_WHITELISTED_CALLER: Curve =
|
||||
Curve::make_reciprocal(16, 28 * 24, percent(96), percent(50), percent(100));
|
||||
const SUP_WHITELISTED_CALLER: Curve =
|
||||
Curve::make_reciprocal(1, 28, percent(20), percent(5), percent(50));
|
||||
|
||||
const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo<Balance, BlockNumber>); 15] = [
|
||||
(
|
||||
0,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "root",
|
||||
max_deciding: 1,
|
||||
decision_deposit: 100 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 12 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_ROOT,
|
||||
min_support: SUP_ROOT,
|
||||
},
|
||||
),
|
||||
(
|
||||
1,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "whitelisted_caller",
|
||||
max_deciding: 100,
|
||||
decision_deposit: 10 * GRAND,
|
||||
prepare_period: 6 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 4 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_WHITELISTED_CALLER,
|
||||
min_support: SUP_WHITELISTED_CALLER,
|
||||
},
|
||||
),
|
||||
(
|
||||
10,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "staking_admin",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 5 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_STAKING_ADMIN,
|
||||
min_support: SUP_STAKING_ADMIN,
|
||||
},
|
||||
),
|
||||
(
|
||||
11,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "treasurer",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 1 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_TREASURER,
|
||||
min_support: SUP_TREASURER,
|
||||
},
|
||||
),
|
||||
(
|
||||
12,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "lease_admin",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 5 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_LEASE_ADMIN,
|
||||
min_support: SUP_LEASE_ADMIN,
|
||||
},
|
||||
),
|
||||
(
|
||||
13,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "fellowship_admin",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 5 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_FELLOWSHIP_ADMIN,
|
||||
min_support: SUP_FELLOWSHIP_ADMIN,
|
||||
},
|
||||
),
|
||||
(
|
||||
14,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "general_admin",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 5 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_GENERAL_ADMIN,
|
||||
min_support: SUP_GENERAL_ADMIN,
|
||||
},
|
||||
),
|
||||
(
|
||||
15,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "auction_admin",
|
||||
max_deciding: 10,
|
||||
decision_deposit: 5 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_AUCTION_ADMIN,
|
||||
min_support: SUP_AUCTION_ADMIN,
|
||||
},
|
||||
),
|
||||
(
|
||||
20,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "referendum_canceller",
|
||||
max_deciding: 1_000,
|
||||
decision_deposit: 10 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 14 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_REFERENDUM_CANCELLER,
|
||||
min_support: SUP_REFERENDUM_CANCELLER,
|
||||
},
|
||||
),
|
||||
(
|
||||
21,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "referendum_killer",
|
||||
max_deciding: 1_000,
|
||||
decision_deposit: 50 * GRAND,
|
||||
prepare_period: 8 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 8 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_REFERENDUM_KILLER,
|
||||
min_support: SUP_REFERENDUM_KILLER,
|
||||
},
|
||||
),
|
||||
(
|
||||
30,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "small_tipper",
|
||||
max_deciding: 200,
|
||||
decision_deposit: 1 * 3 * CENTS,
|
||||
prepare_period: 1 * MINUTES,
|
||||
decision_period: 14 * MINUTES,
|
||||
confirm_period: 4 * MINUTES,
|
||||
min_enactment_period: 1 * MINUTES,
|
||||
min_approval: APP_SMALL_TIPPER,
|
||||
min_support: SUP_SMALL_TIPPER,
|
||||
},
|
||||
),
|
||||
(
|
||||
31,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "big_tipper",
|
||||
max_deciding: 100,
|
||||
decision_deposit: 10 * 3 * CENTS,
|
||||
prepare_period: 4 * MINUTES,
|
||||
decision_period: 14 * MINUTES,
|
||||
confirm_period: 12 * MINUTES,
|
||||
min_enactment_period: 3 * MINUTES,
|
||||
min_approval: APP_BIG_TIPPER,
|
||||
min_support: SUP_BIG_TIPPER,
|
||||
},
|
||||
),
|
||||
(
|
||||
32,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "small_spender",
|
||||
max_deciding: 50,
|
||||
decision_deposit: 100 * 3 * CENTS,
|
||||
prepare_period: 10 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 10 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_SMALL_SPENDER,
|
||||
min_support: SUP_SMALL_SPENDER,
|
||||
},
|
||||
),
|
||||
(
|
||||
33,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "medium_spender",
|
||||
max_deciding: 50,
|
||||
decision_deposit: 200 * 3 * CENTS,
|
||||
prepare_period: 10 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 12 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_MEDIUM_SPENDER,
|
||||
min_support: SUP_MEDIUM_SPENDER,
|
||||
},
|
||||
),
|
||||
(
|
||||
34,
|
||||
pallet_referenda::TrackInfo {
|
||||
name: "big_spender",
|
||||
max_deciding: 50,
|
||||
decision_deposit: 400 * 3 * CENTS,
|
||||
prepare_period: 10 * MINUTES,
|
||||
decision_period: 20 * MINUTES,
|
||||
confirm_period: 14 * MINUTES,
|
||||
min_enactment_period: 5 * MINUTES,
|
||||
min_approval: APP_BIG_SPENDER,
|
||||
min_support: SUP_BIG_SPENDER,
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
pub struct TracksInfo;
|
||||
impl pallet_referenda::TracksInfo<Balance, BlockNumber> for TracksInfo {
|
||||
type Id = u16;
|
||||
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, ()> {
|
||||
if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) {
|
||||
match system_origin {
|
||||
frame_system::RawOrigin::Root => Ok(0),
|
||||
_ => Err(()),
|
||||
}
|
||||
} else if let Ok(custom_origin) = origins::Origin::try_from(id.clone()) {
|
||||
match custom_origin {
|
||||
origins::Origin::WhitelistedCaller => Ok(1),
|
||||
// General admin
|
||||
origins::Origin::StakingAdmin => Ok(10),
|
||||
origins::Origin::Treasurer => Ok(11),
|
||||
origins::Origin::LeaseAdmin => Ok(12),
|
||||
origins::Origin::FellowshipAdmin => Ok(13),
|
||||
origins::Origin::GeneralAdmin => Ok(14),
|
||||
origins::Origin::AuctionAdmin => Ok(15),
|
||||
// Referendum admins
|
||||
origins::Origin::ReferendumCanceller => Ok(20),
|
||||
origins::Origin::ReferendumKiller => Ok(21),
|
||||
// Limited treasury spenders
|
||||
origins::Origin::SmallTipper => Ok(30),
|
||||
origins::Origin::BigTipper => Ok(31),
|
||||
origins::Origin::SmallSpender => Ok(32),
|
||||
origins::Origin::MediumSpender => Ok(33),
|
||||
origins::Origin::BigSpender => Ok(34),
|
||||
_ => Err(()),
|
||||
}
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
||||
pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
|
||||
Reference in New Issue
Block a user