Skip to content

Commit

Permalink
Merge pull request #183 from galacticcouncil/feat/governance
Browse files Browse the repository at this point in the history
feat!: governance
  • Loading branch information
jak-pan authored Mar 31, 2021
2 parents c54efcf + 02b9803 commit de06183
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 54 deletions.
29 changes: 25 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use hydra_dx_runtime::pallet_claims::EthereumAddress;
use hydra_dx_runtime::{
AccountId, AssetRegistryConfig, AuthorityDiscoveryConfig, BabeConfig, BalancesConfig, ClaimsConfig, CouncilConfig,
ElectionsConfig, FaucetConfig, GenesisConfig, GrandpaConfig, ImOnlineConfig, Perbill, SessionConfig, Signature,
StakerStatus, StakingConfig, SudoConfig, SystemConfig, TokensConfig, CORE_ASSET_ID, WASM_BINARY,
StakerStatus, StakingConfig, SudoConfig, SystemConfig, TechnicalCommitteeConfig, TokensConfig, CORE_ASSET_ID,
WASM_BINARY,
};
use pallet_staking::Forcing;
use sc_service::ChainType;
Expand Down Expand Up @@ -253,6 +254,8 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
// Treasury
hex!["6d6f646c70792f74727372790000000000000000000000000000000000000000"].into(),
],
true,
)
Expand Down Expand Up @@ -365,8 +368,21 @@ fn testnet_genesis(
slash_reward_fraction: Perbill::from_percent(10),
..Default::default()
}),
pallet_elections_phragmen: Some(ElectionsConfig { members: vec![] }),
pallet_collective_Instance1: Some(CouncilConfig::default()),
pallet_elections_phragmen: Some(ElectionsConfig {
members: vec![(get_account_id_from_seed::<sr25519::Public>("Alice"), 0)],
}),
pallet_collective_Instance1: Some(CouncilConfig {
members: vec![get_account_id_from_seed::<sr25519::Public>("Alice")],
phantom: Default::default(),
}),
pallet_collective_Instance2: Some(TechnicalCommitteeConfig {
members: vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
],
phantom: Default::default(),
}),
pallet_claims: Some(ClaimsConfig {
claims: create_testnet_claims(),
}),
Expand Down Expand Up @@ -470,7 +486,12 @@ fn lerna_genesis(
..Default::default()
}),
pallet_elections_phragmen: Some(ElectionsConfig { members: vec![] }),
pallet_collective_Instance1: Some(CouncilConfig::default()),
pallet_collective_Instance1: Some(CouncilConfig {
// Intergalactic council member
members: vec![hex!["0abad795adcb5dee45d29528005b1f78d55fc170844babde88df84016c6cd14d"].into()],
phantom: Default::default(),
}),
pallet_collective_Instance2: Some(TechnicalCommitteeConfig::default()),
pallet_claims: Some(ClaimsConfig { claims: vec![] }),
}
}
Expand Down
3 changes: 3 additions & 0 deletions runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pub mod currency {
pub const DOLLARS: Balance = HDX / 10; // 10 HDX ~= 1 $
pub const CENTS: Balance = DOLLARS / 100;
pub const MILLICENTS: Balance = CENTS / 1_000;

pub const FORTUNE: Balance = u128::MAX;
}

pub mod time {
Expand Down Expand Up @@ -46,4 +48,5 @@ pub mod time {

(EPOCH_DURATION_IN_BLOCKS as f64 * SLOT_FILL_RATE) as u64
};
pub const INFINITY: u32 = u32::MAX;
}
117 changes: 67 additions & 50 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use sp_api::impl_runtime_apis;
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_core::{
crypto::KeyTypeId,
u32_trait::{_1, _2, _4},
u32_trait::{_1, _2, _3, _4},
OpaqueMetadata,
};
use sp_runtime::traits::{
Expand Down Expand Up @@ -52,7 +52,7 @@ pub use pallet_timestamp::Call as TimestampCall;
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};

use frame_system::{EnsureOneOf, EnsureRoot};
use frame_system::EnsureRoot;
use sp_runtime::curve::PiecewiseLinear;

use pallet_session::historical as session_historical;
Expand Down Expand Up @@ -161,33 +161,34 @@ pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(call: &Call) -> bool {
match call {
Call::Council(_)
| Call::Faucet(_)
Call::AMM(_)
| Call::AssetRegistry(_)
| Call::Balances(_)
| Call::Currencies(_)
| Call::Tokens(_)
| Call::AssetRegistry(_)
| Call::Offences(_)
| Call::AMM(_)
| Call::Exchange(_)
| Call::Faucet(_)
| Call::MultiTransactionPayment(_)
| Call::Exchange(_) => false,
| Call::Offences(_)
| Call::Tokens(_) => false,

Call::System(_)
| Call::RandomnessCollectiveFlip(_)
Call::AuthorityDiscovery(_)
| Call::Authorship(_)
| Call::Babe(_)
| Call::Claims(_)
| Call::Council(_)
| Call::ElectionProviderMultiPhase(_)
| Call::Elections(_)
| Call::Babe(_)
| Call::Treasury(_)
| Call::Tips(_)
| Call::Timestamp(_)
| Call::Authorship(_)
| Call::Staking(_)
| Call::Session(_)
| Call::Grandpa(_)
| Call::AuthorityDiscovery(_)
| Call::ImOnline(_)
| Call::ElectionProviderMultiPhase(_)
| Call::RandomnessCollectiveFlip(_)
| Call::Scheduler(_)
| Call::Session(_)
| Call::Staking(_)
| Call::System(_)
| Call::TechnicalCommittee(_)
| Call::Timestamp(_)
| Call::Tips(_)
| Call::Treasury(_)
| Call::Identity(_)
| Call::Sudo(_) => true,
}
Expand Down Expand Up @@ -560,38 +561,25 @@ impl pallet_election_provider_multi_phase::Config for Runtime {

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = DOLLARS;
pub const ProposalBondMinimum: Balance = FORTUNE;
pub const SpendPeriod: BlockNumber = DAYS;
pub const Burn: Permill = Permill::from_percent(50);
pub const DataDepositPerByte: Balance = CENTS;
pub const TipCountdown: BlockNumber = DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(20);
pub const TipReportDepositBase: Balance = DOLLARS;
pub const TipReportDepositPerByte: Balance = CENTS;
pub const MaximumReasonLength: u32 = 16384;
pub const Burn: Permill = Permill::from_percent(0);
pub const TreasuryModuleId: ModuleId = ModuleId(*b"py/trsry");
pub OffchainSolutionWeightLimit: Weight = BlockWeights::get().max_block
.saturating_sub(BlockExecutionWeight::get())
.saturating_sub(ExtrinsicBaseWeight::get());
}

type AllCouncilMembers = pallet_collective::EnsureProportionAtLeast<_1, _1, AccountId, CouncilCollective>;
type ManageOrigin = frame_system::EnsureOneOf<AccountId, EnsureRoot<AccountId>, AllCouncilMembers>;

impl pallet_treasury::Config for Runtime {
type ModuleId = TreasuryModuleId;
type Currency = Balances;
type ApproveOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>,
>;
type RejectOrigin = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>,
>;
//type TipReportDepositPerByte = TipReportDepositPerByte;
type ApproveOrigin = ManageOrigin;
type RejectOrigin = ManageOrigin;
type Event = Event;
type OnSlash = ();
//type ProposalRejection = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
Expand All @@ -601,6 +589,15 @@ impl pallet_treasury::Config for Runtime {
type SpendFunds = ();
}

parameter_types! {
pub const DataDepositPerByte: Balance = CENTS;
pub const TipCountdown: BlockNumber = DAYS;
pub const TipFindersFee: Percent = Percent::from_percent(2);
pub const TipReportDepositBase: Balance = 10 * DOLLARS;
pub const TipReportDepositPerByte: Balance = CENTS;
pub const MaximumReasonLength: u32 = 1024;
}

impl pallet_tips::Config for Runtime {
type Event = Event;
type DataDepositPerByte = DataDepositPerByte;
Expand Down Expand Up @@ -635,11 +632,12 @@ impl pallet_session::historical::Config for Runtime {
}

parameter_types! {
pub const CandidacyBond: Balance = 10 * DOLLARS;
// Don't allow runner-ups
pub const CandidacyBond: Balance = FORTUNE;
pub const VotingBond: Balance = DOLLARS;
pub const TermDuration: BlockNumber = 7 * DAYS;
pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 7;
pub const DesiredMembers: u32 = 1;
pub const DesiredRunnersUp: u32 = 0;
pub const ElectionsPhragmenModuleId: LockIdentifier = *b"phrelect";
}

Expand All @@ -648,9 +646,7 @@ impl pallet_elections_phragmen::Config for Runtime {
type ModuleId = ElectionsPhragmenModuleId;
type Currency = Balances;
type ChangeMembers = Council;
// NOTE: this implies that council's genesis members cannot be set directly and must come from
// this module.
type InitializeMembers = Council;
type InitializeMembers = (); // Set to () if defined in chain spec
type CurrencyToVote = U128CurrencyToVote;
type CandidacyBond = CandidacyBond;
type VotingBondBase = ();
Expand Down Expand Up @@ -689,9 +685,10 @@ impl pallet_babe::Config for Runtime {

parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 5 * DAYS;
pub const CouncilMaxProposals: u32 = 100;
pub const ProposalVotesRequired: u32 = 3;
pub const ProposalMininumDeposit: Balance = 0;
pub const CouncilMaxProposals: u32 = 10;
pub const ProposalVotesRequired: u32 = 1;
pub const ProposalMininumDeposit: Balance = FORTUNE;
pub const CouncilMaxMembers: u32 = 1;
}

type CouncilCollective = pallet_collective::Instance1;
Expand All @@ -701,7 +698,25 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type Event = Event;
type MotionDuration = CouncilMotionDuration;
type MaxProposals = CouncilMaxProposals;
type MaxMembers = ();
type MaxMembers = CouncilMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}

parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 7 * DAYS;
pub const TechnicalMaxProposals: u32 = 10;
pub const TechnicalMaxMembers: u32 = 10;
}

type TechnicalCollective = pallet_collective::Instance2;
impl pallet_collective::Config<TechnicalCollective> for Runtime {
type Origin = Origin;
type Proposal = Call;
type Event = Event;
type MotionDuration = TechnicalMotionDuration;
type MaxProposals = TechnicalMaxProposals;
type MaxMembers = TechnicalMaxMembers;
type DefaultVote = pallet_collective::PrimeDefaultVote;
type WeightInfo = ();
}
Expand Down Expand Up @@ -845,6 +860,7 @@ construct_runtime!(
Session: pallet_session::{Module, Call, Storage, Event, Config<T>},
Elections: pallet_elections_phragmen::{Module, Call, Storage, Event<T>, Config<T>},
Council: pallet_collective::<Instance1>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
TechnicalCommittee: pallet_collective::<Instance2>::{Module, Call, Storage, Origin<T>, Event<T>, Config<T>},
AuthorityDiscovery: pallet_authority_discovery::{Module, Call, Config},
ImOnline: pallet_im_online::{Module, Call, Storage, Event<T>, ValidateUnsigned, Config<T>},
Offences: pallet_offences::{Module, Call, Storage, Event},
Expand Down Expand Up @@ -1141,6 +1157,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, exchange, ExchangeBench::<Runtime>);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_collective, Council);
add_benchmark!(params, batches, pallet_identity, Identity);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Expand Down

0 comments on commit de06183

Please sign in to comment.