Skip to content

Commit

Permalink
Feat: Basic governance config for InvArch
Browse files Browse the repository at this point in the history
  • Loading branch information
Anny0nn committed Oct 31, 2024
1 parent 01304c5 commit e2733e3
Show file tree
Hide file tree
Showing 9 changed files with 608 additions and 15 deletions.
7 changes: 7 additions & 0 deletions invarch/Cargo.lock

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

7 changes: 7 additions & 0 deletions invarch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ frame-try-runtime = { git = "https://github.com/paritytech/polkadot-sdk.git", br
pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-contracts = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-identity = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-insecure-randomness-collective-flip = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-message-queue = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-referenda = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-session = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
Expand All @@ -72,7 +77,9 @@ pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/parityt
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-tx-pause = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
pallet-whitelist = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407" }
sp-consensus = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "stable2407" }
Expand Down
22 changes: 22 additions & 0 deletions invarch/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ frame-try-runtime = { workspace = true, optional = true }
pallet-aura = { workspace = true }
pallet-authorship = { workspace = true }
pallet-balances = { workspace = true }
pallet-collective = { workspace = true }
pallet-contracts = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-identity = { workspace = true }
pallet-insecure-randomness-collective-flip = { workspace = true }
pallet-message-queue = { workspace = true }
pallet-preimage = { workspace = true }
pallet-referenda = { workspace = true }
pallet-scheduler = { workspace = true }
pallet-session = { workspace = true }
pallet-sudo = { workspace = true }
pallet-timestamp = { workspace = true }
Expand All @@ -52,7 +57,9 @@ pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-treasury = { workspace = true }
pallet-tx-pause = { workspace = true }
pallet-utility = { workspace = true }
pallet-whitelist = { workspace = true }
sp-api = { workspace = true }
sp-arithmetic = { workspace = true }
sp-block-builder = { workspace = true }
sp-consensus-aura = { workspace = true }
sp-core = { workspace = true }
Expand Down Expand Up @@ -137,11 +144,16 @@ std = [
"pallet-balances/std",
"pallet-checked-inflation/std",
"pallet-collator-selection/std",
"pallet-collective/std",
"pallet-contracts/std",
"pallet-conviction-voting/std",
"pallet-dao-manager/std",
"pallet-dao-staking/std",
"pallet-identity/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-preimage/std",
"pallet-referenda/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
Expand All @@ -150,12 +162,14 @@ std = [
"pallet-treasury/std",
"pallet-tx-pause/std",
"pallet-utility/std",
"pallet-whitelist/std",
"pallet-xcm/std",
"parachain-info/std",
"polkadot-parachain/std",
"polkadot-runtime-common/std",
"scale-info/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
"sp-core/std",
Expand All @@ -181,9 +195,13 @@ runtime-benchmarks = [
"pallet-balances/runtime-benchmarks",
"pallet-checked-inflation/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-dao-manager/runtime-benchmarks",
"pallet-dao-staking/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand All @@ -202,10 +220,14 @@ try-runtime = [
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-referenda/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"pallet-collective/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-whitelist/try-runtime",
]
17 changes: 6 additions & 11 deletions invarch/runtime/src/balances.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
AccountId, Balance, Balances, BlockNumber, ExtrinsicBaseWeight, Runtime, RuntimeEvent,
RuntimeFreezeReason, RuntimeHoldReason, System, Treasury, DAYS, EXISTENTIAL_DEPOSIT, MICROUNIT,
MILLIUNIT, UNIT,
AccountId, Balance, Balances, BlockNumber, CouncilRejectOrigin, ExtrinsicBaseWeight, Runtime,
RuntimeEvent, RuntimeFreezeReason, RuntimeHoldReason, System, Treasury, TreasurySpender, DAYS,
EXISTENTIAL_DEPOSIT, MICROUNIT, MILLIUNIT, UNIT,
};
use frame_support::{
pallet_prelude::ConstU32,
Expand All @@ -16,7 +16,7 @@ use frame_support::{
},
PalletId,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use frame_system::EnsureSignedBy;
use polkadot_runtime_common::SlowAdjustingFeeUpdate;
use sp_runtime::{
traits::{AccountIdConversion, IdentityLookup},
Expand Down Expand Up @@ -159,22 +159,17 @@ impl pallet_treasury::Config for Runtime {
type BeneficiaryLookup = IdentityLookup<Self::Beneficiary>;
type PalletId = TreasuryPalletId;
type Currency = Balances;
// type ApproveOrigin = EnsureRoot<AccountId>;
type RejectOrigin = EnsureRoot<AccountId>;
type RejectOrigin = CouncilRejectOrigin;
type RuntimeEvent = RuntimeEvent;
// type OnSlash = ();
type Paymaster = PayFromAccount<Balances, TreasuryAccount>;
type PayoutPeriod = PayoutSpendPeriod;
// type ProposalBond = ProposalBond;
// type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = ();
type BurnDestination = ();
type SpendFunds = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
// type ProposalBondMaximum = ();
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>;
type SpendOrigin = TreasurySpender;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
30 changes: 30 additions & 0 deletions invarch/runtime/src/governance/councils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//! Councils for Governance
use super::*;

pub type TinkerCouncil = pallet_collective::Instance1;

parameter_types! {
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
pub MaxMotionDuration: u32 = 3 * DAYS ;
pub MaxProposals: u32 = 20;
pub MaxMembers: u32 = 5;

}

impl pallet_collective::Config<TinkerCouncil> for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type Proposal = RuntimeCall;
/// The maximum amount of time (in blocks) council members to vote on motions.
/// Motions may end in fewer blocks if enough votes are cast to determine the result.
type MotionDuration = MaxMotionDuration;
/// The maximum number of proposals that can be open in council at once.
type MaxProposals = MaxProposals;
/// The maximum number of council members.
type MaxMembers = MaxMembers;
type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote;
type WeightInfo = pallet_collective::weights::SubstrateWeight<Runtime>;
type SetMembersOrigin = EitherOf<CouncilApproveOrigin, CouncilAdmin>;
type MaxProposalWeight = MaxProposalWeight;
}
86 changes: 86 additions & 0 deletions invarch/runtime/src/governance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use self::councils::TinkerCouncil;

use super::*;
// use crate::xcm_config::CollectivesLocation;
use frame_support::{parameter_types, traits::EitherOf};

use frame_system::EnsureRootWithSuccess;

mod origins;
pub use origins::{
pallet_custom_origins, CouncilAdmin, GeneralManagement, ReferendumCanceller, ReferendumKiller,
Spender, WhitelistedCaller,
};
mod tracks;
pub use tracks::TracksInfo;

mod councils;

parameter_types! {
pub const VoteLockingPeriod: BlockNumber = 7 * DAYS;
}

impl pallet_conviction_voting::Config for Runtime {
type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight<Runtime>;
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 = UNIT;
pub const UndecidingTimeout: BlockNumber = 14 * DAYS;
}

parameter_types! {
pub const MaxBalance: Balance = Balance::max_value();
}

pub type AllCouncil = pallet_collective::EnsureProportionAtLeast<AccountId, TinkerCouncil, 1, 1>;
pub type CouncilMoreThanApprove =
pallet_collective::EnsureProportionMoreThan<AccountId, TinkerCouncil, 3, 5>;
pub type ConcilHalf = pallet_collective::EnsureProportionAtLeast<AccountId, TinkerCouncil, 1, 2>;
pub type CouncilThreeFifths =
pallet_collective::EnsureProportionAtLeast<AccountId, TinkerCouncil, 3, 5>;

pub type TreasurySpender = EitherOf<EnsureRootWithSuccess<AccountId, MaxBalance>, Spender>;
pub type RootOrGeneralManagement = EitherOf<EnsureRoot<AccountId>, GeneralManagement>;
pub type CouncilApproveOrigin = EitherOf<EnsureRoot<AccountId>, CouncilThreeFifths>;
pub type CouncilRejectOrigin = EitherOf<EnsureRoot<AccountId>, ConcilHalf>;

impl pallet_custom_origins::Config for Runtime {}

impl pallet_whitelist::Config for Runtime {
type WeightInfo = pallet_whitelist::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WhitelistOrigin = CouncilApproveOrigin;
type DispatchWhitelistedOrigin = EitherOf<EnsureRoot<Self::AccountId>, WhitelistedCaller>;
type Preimages = Preimage;
}

impl pallet_referenda::Config for Runtime {
type WeightInfo = pallet_referenda::weights::SubstrateWeight<Runtime>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type Scheduler = Scheduler;
type Currency = Balances;
type SubmitOrigin = frame_system::EnsureSigned<AccountId>;
type CancelOrigin =
EitherOf<EitherOf<EnsureRoot<AccountId>, ReferendumCanceller>, CouncilMoreThanApprove>;
type KillOrigin = EitherOf<EitherOf<EnsureRoot<AccountId>, ReferendumKiller>, AllCouncil>;
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;
}
Loading

0 comments on commit e2733e3

Please sign in to comment.