From c83e1fbc51cd4e85ec2fc8137b9f11d3c4dac0cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Andr=C3=A9s=20Dorado=20Su=C3=A1rez?= Date: Fri, 5 Apr 2024 16:49:41 -0500 Subject: [PATCH] Kreivo Collective (#353) * wip(kreivo-runtime): implement ranked collective for kreivo * change(kreivo-runtime): configure the kreivo collective and root governance --- Cargo.lock | 1 + Cargo.toml | 1 + runtime/kreivo/Cargo.toml | 4 ++ runtime/kreivo/src/collective/governance.rs | 35 ++++++++++++++ runtime/kreivo/src/collective/mod.rs | 27 +++++++++++ runtime/kreivo/src/collective/tracks.rs | 52 +++++++++++++++++++++ runtime/kreivo/src/lib.rs | 7 +++ 7 files changed, 127 insertions(+) create mode 100644 runtime/kreivo/src/collective/governance.rs create mode 100644 runtime/kreivo/src/collective/mod.rs create mode 100644 runtime/kreivo/src/collective/tracks.rs diff --git a/Cargo.lock b/Cargo.lock index 9111d7e6..14cffed1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4715,6 +4715,7 @@ dependencies = [ "pallet-payments", "pallet-preimage", "pallet-proxy", + "pallet-ranked-collective", "pallet-referenda", "pallet-scheduler", "pallet-session", diff --git a/Cargo.toml b/Cargo.toml index 5ca389a3..c14edf6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -137,6 +137,7 @@ pallet-multisig = { default-features = false, git = "https://github.com/virto-ne pallet-nfts = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } pallet-preimage = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } pallet-proxy = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } +pallet-ranked-collective = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } pallet-referenda = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } pallet-remark = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } pallet-scheduler = { default-features = false, git = "https://github.com/virto-network/polkadot-sdk", branch = "release-virto-v1.5.0" } diff --git a/runtime/kreivo/Cargo.toml b/runtime/kreivo/Cargo.toml index fe280ca6..19c10626 100644 --- a/runtime/kreivo/Cargo.toml +++ b/runtime/kreivo/Cargo.toml @@ -49,6 +49,7 @@ pallet-multisig = { workspace = true } pallet-utility = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } +pallet-ranked-collective = { workspace = true } pallet-referenda = { workspace = true } pallet-scheduler = { workspace = true } pallet-session = { workspace = true } @@ -137,6 +138,7 @@ std = [ "pallet-payments/std", "pallet-preimage/std", "pallet-proxy/std", + "pallet-ranked-collective/std", "pallet-referenda/std", "pallet-referenda-tracks/std", "pallet-scheduler/std", @@ -200,6 +202,7 @@ runtime-benchmarks = [ "pallet-payments/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-ranked-collective/runtime-benchmarks", "pallet-referenda/runtime-benchmarks", "pallet-referenda-tracks/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", @@ -241,6 +244,7 @@ try-runtime = [ "pallet-payments/try-runtime", "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", + "pallet-ranked-collective/try-runtime", "pallet-referenda/try-runtime", "pallet-referenda-tracks/try-runtime", "pallet-scheduler/try-runtime", diff --git a/runtime/kreivo/src/collective/governance.rs b/runtime/kreivo/src/collective/governance.rs new file mode 100644 index 00000000..91f0ceb2 --- /dev/null +++ b/runtime/kreivo/src/collective/governance.rs @@ -0,0 +1,35 @@ +use super::*; + +use pallet_communities::origin::AsSignedByCommunity; +use parachains_common::kusama::currency::QUID; +use sp_core::ConstU128; + +pub type KreivoTracksInstance = pallet_referenda_tracks::Instance1; +pub type KreivoReferendaInstance = pallet_referenda::Instance1; + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = QUID; + pub const UndecidingTimeout: BlockNumber = 14 * DAYS; +} + +impl pallet_referenda::Config for Runtime { + type WeightInfo = pallet_referenda::weights::SubstrateWeight; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + // Communities can submit proposals. + type SubmitOrigin = AsEnsureOriginWithArg>; + type CancelOrigin = EnsureRoot; + type KillOrigin = EnsureRoot; + type Slash = (); + type Votes = pallet_ranked_collective::Votes; + type Tally = pallet_ranked_collective::TallyOf; + type SubmissionDeposit = ConstU128<0>; + type MaxQueued = ConstU32<10>; + type UndecidingTimeout = ConstU32<{ 2 * DAYS }>; + type AlarmInterval = ConstU32<1>; + type Tracks = tracks::TracksInfo; + type Preimages = Preimage; +} diff --git a/runtime/kreivo/src/collective/mod.rs b/runtime/kreivo/src/collective/mod.rs new file mode 100644 index 00000000..e7306646 --- /dev/null +++ b/runtime/kreivo/src/collective/mod.rs @@ -0,0 +1,27 @@ +use super::*; + +use frame_system::EnsureRootWithSuccess; +use sp_core::ConstU16; + +pub mod governance; +pub mod tracks; + +pub type KreivoCollectiveInstance = pallet_ranked_collective::Instance1; +impl pallet_ranked_collective::Config for Runtime { + type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight; + type RuntimeEvent = RuntimeEvent; + + // Initially, members of kreivo collective are promoted via governance action + // In the future, it's expected to have an auxilliary pallet to observe the + // criteria for ranking + type PromoteOrigin = EnsureRootWithSuccess>; + + // Initially, members of kreivo collective are demoted via governance action + // In the future, it's expected to have an auxilliary pallet to observe the + // criteria for ranking + type DemoteOrigin = EnsureRootWithSuccess>; + + type Polls = KreivoReferenda; + type MinRankOfClass = (); + type VoteWeight = pallet_ranked_collective::Linear; +} diff --git a/runtime/kreivo/src/collective/tracks.rs b/runtime/kreivo/src/collective/tracks.rs new file mode 100644 index 00000000..ea56b264 --- /dev/null +++ b/runtime/kreivo/src/collective/tracks.rs @@ -0,0 +1,52 @@ +use super::*; + +use pallet_referenda::{impl_tracksinfo_get, Track}; +use sp_runtime::str_array as s; +use sp_std::borrow::Cow; + +pub type TrackId = u16; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = TrackId; + type RuntimeOrigin = ::PalletsOrigin; + type TracksIter = pallet_referenda::StaticTracksIter; + + fn tracks() -> Self::TracksIter { + const DATA: [pallet_referenda::Track; 1] = [Track { + id: 0, + info: pallet_referenda::TrackInfo { + name: s("Root"), + max_deciding: 1, + decision_deposit: 0, + prepare_period: 15 * MINUTES, + decision_period: 4 * DAYS, + confirm_period: 15 * MINUTES, + min_enactment_period: 1, + min_approval: pallet_referenda::Curve::LinearDecreasing { + length: Perbill::from_percent(100), + floor: Perbill::from_percent(90), + 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), + }, + }, + }]; + DATA.iter().map(Cow::Borrowed) + } + + fn track_for(id: &Self::RuntimeOrigin) -> Result { + if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) { + match system_origin { + frame_system::RawOrigin::Root => Ok(0), + _ => Err(()), + } + } else { + Err(()) + } + } +} +impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); diff --git a/runtime/kreivo/src/lib.rs b/runtime/kreivo/src/lib.rs index d874dbbd..e947f344 100644 --- a/runtime/kreivo/src/lib.rs +++ b/runtime/kreivo/src/lib.rs @@ -71,6 +71,9 @@ pub use polkadot_runtime_common::{prod_or_fast, BlockHashCount, SlowAdjustingFee pub use weights::{BlockExecutionWeight, ExtrinsicBaseWeight}; +// Kreivo Governance +pub mod collective; + // Virto toolchain pub mod payments; @@ -196,6 +199,8 @@ construct_runtime!( // Governance Treasury: pallet_treasury = 50, + KreivoCollective: pallet_ranked_collective:: = 51, + KreivoReferenda: pallet_referenda:: = 52, // Virto Tooling Payments: pallet_payments = 60, @@ -703,6 +708,8 @@ mod benches { [pallet_utility, Utility] [pallet_assets, Assets] [pallet_proxy, Proxy] + [pallet_referenda, KreivoReferenda] + [pallet_ranked_collective, KreivoCollective] [pallet_payments, Payments] [pallet_communities, Communities] [pallet_referenda_tracks, CommunityTracks]