Skip to content
Draft
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 changes: 5 additions & 0 deletions tinkernet/Cargo.lock

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

5 changes: 5 additions & 0 deletions tinkernet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk.git", bran
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-utility = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-referenda = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-conviction-voting = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
pallet-whitelist = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }

# Substrate Primitive Dependencies
sp-api = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.6.0", default-features = false }
Expand Down
18 changes: 18 additions & 0 deletions tinkernet/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,14 @@ pallet-treasury = { workspace = true }
pallet-transaction-payment = { workspace = true }
pallet-transaction-payment-rpc-runtime-api = { workspace = true }
pallet-utility = { workspace = true }
pallet-referenda = { workspace = true }
pallet-conviction-voting = { workspace = true }
pallet-whitelist = { workspace = true }
pallet-collective = { workspace = true }

# Substrate Primitive Dependencies
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 @@ -172,9 +177,14 @@ std = [
"pallet-utility/std",
"pallet-xcm/std",
"pallet-collator-selection/std",
"pallet-referenda/std",
"pallet-conviction-voting/std",
"pallet-whitelist/std",
"pallet-collective/std",
"parachain-info/std",
"polkadot-parachain/std",
"sp-api/std",
"sp-arithmetic/std",
"sp-block-builder/std",
"sp-consensus-aura/std",
"sp-core/std",
Expand Down Expand Up @@ -224,6 +234,10 @@ runtime-benchmarks = [
"pallet-rings/runtime-benchmarks",
"pallet-ocif-staking/runtime-benchmarks",
"pallet-checked-inflation/runtime-benchmarks",
"pallet-referenda/runtime-benchmarks",
"pallet-conviction-voting/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
]

try-runtime = [
Expand Down Expand Up @@ -267,4 +281,8 @@ try-runtime = [
"pallet-checked-inflation/try-runtime",
"pallet-rings/try-runtime",
"pallet-asset-tx-payment/try-runtime",
"pallet-referenda/try-runtime",
"pallet-conviction-voting/try-runtime",
"pallet-whitelist/try-runtime",
"pallet-collective/try-runtime",
]
1 change: 1 addition & 0 deletions tinkernet/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod currency {
use crate::Balance;

pub const UNIT: Balance = 1_000_000_000_000;
pub const GRAND: Balance = UNIT * 1_000;
pub const MILLIUNIT: Balance = 1_000_000_000;
pub const MICROUNIT: Balance = 1_000_000;

Expand Down
30 changes: 30 additions & 0 deletions tinkernet/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 tinkernet/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;
}
112 changes: 112 additions & 0 deletions tinkernet/runtime/src/governance/origins.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//! 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 for managing the composition of the council.
CouncilAdmin,
/// 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 $??? from the treasury at once.
SmallSpender,
/// Origin able to spend up to $??? 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!(
CouncilAdmin,
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