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

InvArch Governance Phase 1 #179

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
5,025 changes: 2,355 additions & 2,670 deletions invarch/Cargo.lock

Large diffs are not rendered by default.

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
24 changes: 24 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 @@ -101,6 +108,8 @@ parachain-info = { workspace = true }

[features]

fast-net = []

metadata-hash = ["substrate-wasm-builder/metadata-hash"]

default = ["std"]
Expand Down Expand Up @@ -137,11 +146,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 +164,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 +197,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 +222,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 Council = 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<Council> 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 = CouncilApproveOrigin;
type MaxProposalWeight = MaxProposalWeight;
}
85 changes: 85 additions & 0 deletions invarch/runtime/src/governance/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use self::councils::Council;

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, 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, Council, 1, 1>;
pub type CouncilMoreThanApprove =
pallet_collective::EnsureProportionMoreThan<AccountId, Council, 3, 5>;
pub type ConcilHalf = pallet_collective::EnsureProportionAtLeast<AccountId, Council, 1, 2>;
pub type CouncilThreeFifths = pallet_collective::EnsureProportionAtLeast<AccountId, Council, 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;
}
109 changes: 109 additions & 0 deletions invarch/runtime/src/governance/origins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//! Custom origins for governance interventions.

pub use pallet_custom_origins::*;

#[frame_support::pallet]
pub mod pallet_custom_origins {
use crate::{Balance, 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 able to cancel a referenda.
ReferendumCanceller,
/// Origin able to kill referenda.
ReferendumKiller,
/// Origin able to dispatch a whitelisted call.
WhitelistedCaller,
/// Origin for general management that does not require a runtime upgrade.
GeneralManagement,
/// Origin able to spend around 10K from the treasury at once.
SmallSpender,
/// Origin able to spend up to 1MIL from the treasury at once.
BigSpender,
}

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!(
ReferendumCanceller,
ReferendumKiller,
WhitelistedCaller,
GeneralManagement,
);

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> {
SmallSpender = 10 * GRAND,
BigSpender = 1_000 * GRAND,
}
}
}
Loading
Loading