Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kreivo Collective #353

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
4 changes: 4 additions & 0 deletions runtime/kreivo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
35 changes: 35 additions & 0 deletions runtime/kreivo/src/collective/governance.rs
Original file line number Diff line number Diff line change
@@ -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<KreivoReferendaInstance> for Runtime {
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Self>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = Balances;
// Communities can submit proposals.
type SubmitOrigin = AsEnsureOriginWithArg<AsSignedByCommunity<Self>>;
type CancelOrigin = EnsureRoot<AccountId>;
type KillOrigin = EnsureRoot<AccountId>;
type Slash = ();
type Votes = pallet_ranked_collective::Votes;
type Tally = pallet_ranked_collective::TallyOf<Runtime, KreivoCollectiveInstance>;
type SubmissionDeposit = ConstU128<0>;
type MaxQueued = ConstU32<10>;
type UndecidingTimeout = ConstU32<{ 2 * DAYS }>;
type AlarmInterval = ConstU32<1>;
type Tracks = tracks::TracksInfo;
type Preimages = Preimage;
}
27 changes: 27 additions & 0 deletions runtime/kreivo/src/collective/mod.rs
Original file line number Diff line number Diff line change
@@ -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<KreivoCollectiveInstance> for Runtime {
type WeightInfo = pallet_ranked_collective::weights::SubstrateWeight<Self>;
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<Self::AccountId, ConstU16<65535>>;

// 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<Self::AccountId, ConstU16<65535>>;

type Polls = KreivoReferenda;
type MinRankOfClass = ();
type VoteWeight = pallet_ranked_collective::Linear;
}
52 changes: 52 additions & 0 deletions runtime/kreivo/src/collective/tracks.rs
Original file line number Diff line number Diff line change
@@ -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<Balance, BlockNumber> for TracksInfo {
type Id = TrackId;
type RuntimeOrigin = <RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin;
type TracksIter = pallet_referenda::StaticTracksIter<Self::Id, Balance, BlockNumber>;

fn tracks() -> Self::TracksIter {
const DATA: [pallet_referenda::Track<TrackId, Balance, BlockNumber>; 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<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 {
Err(())
}
}
}
impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber);
7 changes: 7 additions & 0 deletions runtime/kreivo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -196,6 +199,8 @@ construct_runtime!(

// Governance
Treasury: pallet_treasury = 50,
KreivoCollective: pallet_ranked_collective::<Instance1> = 51,
KreivoReferenda: pallet_referenda::<Instance1> = 52,

// Virto Tooling
Payments: pallet_payments = 60,
Expand Down Expand Up @@ -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]
Expand Down