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

Adds treasury and other governance pallets #40

Merged
merged 3 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ where
pub fn picasso_dev() -> picasso::ChainSpec {
//TODO check properties
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "$PICA".into());
properties.insert("tokenSymbol".into(), "PICA".into());
properties.insert("tokenDecimals".into(), 12.into());

picasso::ChainSpec::from_genesis(
Expand Down
12 changes: 6 additions & 6 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "runtime-common"
version = "0.8.30"
authors = ["Parity Technologies <admin@parity.io>"]
authors = ["Composable Developers <admin@composable.finance>"]
edition = "2018"

[package.metadata.docs.rs]
Expand All @@ -15,22 +15,21 @@ codec = { package = "parity-scale-codec", version = "2.0.0", default-features =
executive = { package = "frame-executive", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
frame-system = { package = "frame-system", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
frame-support = { package = "frame-support", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
node-primitives = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
polkadot-runtime-common = { git = "https://github.com/paritytech/polkadot", tag = "v0.9.8", default-features = false }
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", tag = "v0.9.8", default-features = false }

collator-selection = { package = "pallet-collator-selection", git = 'https://github.com/paritytech/cumulus', branch = 'polkadot-v0.9.8', default-features = false }
balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
collective = { package = "pallet-collective", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }

[dev-dependencies]
serde = { version = "1.0.119" }
authorship = { package = "pallet-authorship", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }

[build-dependencies]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8" }


[features]
default = ["std"]
std = [
Expand All @@ -43,6 +42,7 @@ std = [
'frame-system/std',
'collator-selection/std',
'balances/std',
'collective/std',
'node-primitives/std',
'polkadot-runtime-common/std',
'polkadot-primitives/std',
Expand Down
50 changes: 43 additions & 7 deletions runtime/common/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub type NegativeImbalance<T> = <balances::Pallet<T> as Currency<<T as frame_sys
pub struct ToStakingPot<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for ToStakingPot<R>
where
R: balances::Config + collator_selection::Config,
R: balances::Config + collator_selection::Config + treasury::Config<Currency=balances::Pallet<R>>,
<R as frame_system::Config>::AccountId: From<polkadot_primitives::v1::AccountId>,
<R as frame_system::Config>::AccountId: Into<polkadot_primitives::v1::AccountId>,
<R as frame_system::Config>::Event: From<balances::Event<R>>,
Expand All @@ -40,11 +40,12 @@ where
);
// deposit then slash the amount to burn fees
if <balances::Pallet<R>>::can_slash(&staking_pot, slash_amount) {
// TODO: enrich treasury with the negative imbalance.
let (_negative_imbalanbce, _) = <balances::Pallet<R>>::slash(
let (imbalance, _) = <balances::Pallet<R>>::slash(
&staking_pot,
slash_amount,
);
// give treasury the remaining half
<treasury::Pallet<R> as OnUnbalanced<_>>::on_unbalanced(imbalance);
scruffy-dev marked this conversation as resolved.
Show resolved Hide resolved
}

<frame_system::Pallet<R>>::deposit_event(balances::Event::Deposit(
Expand All @@ -58,7 +59,7 @@ where
pub struct DealWithFees<R>(sp_std::marker::PhantomData<R>);
impl<R> OnUnbalanced<NegativeImbalance<R>> for DealWithFees<R>
where
R: balances::Config + collator_selection::Config,
R: balances::Config + collator_selection::Config + treasury::Config<Currency=balances::Pallet<R>>,
<R as frame_system::Config>::AccountId: From<polkadot_primitives::v1::AccountId>,
<R as frame_system::Config>::AccountId: Into<polkadot_primitives::v1::AccountId>,
<R as frame_system::Config>::Event: From<balances::Event<R>>,
Expand All @@ -84,9 +85,10 @@ mod tests {
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, IdentityLookup},
Perbill,
Perbill, Permill,
};
use collator_selection::IdentityCollator;
use crate::{DAYS, Balance, BlockNumber, constants::PICA};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
Expand All @@ -99,6 +101,7 @@ mod tests {
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Balances: balances::{Pallet, Call, Storage, Config<T>, Event<T>},
Treasury: treasury::{Pallet, Call, Storage, Config, Event<T>} = 31,
CollatorSelection: collator_selection::{Pallet, Call, Storage, Event<T>},
}
);
Expand Down Expand Up @@ -127,7 +130,7 @@ mod tests {
type DbWeight = ();
type Version = ();
type PalletInfo = PalletInfo;
type AccountData = balances::AccountData<u64>;
type AccountData = balances::AccountData<u128>;
type OnNewAccount = ();
type OnKilledAccount = ();
type SystemWeightInfo = ();
Expand All @@ -140,7 +143,7 @@ mod tests {
}

impl balances::Config for Test {
type Balance = u64;
type Balance = u128;
type Event = Event;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
Expand Down Expand Up @@ -197,6 +200,36 @@ mod tests {
type EventHandler = ();
}

parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"picatrsy");
/// percentage of proposal that most be bonded by the proposer
pub const ProposalBond: Permill = Permill::from_percent(5);
// TODO: rationale?
pub const ProposalBondMinimum: Balance = 5 * PICA;
pub const SpendPeriod: BlockNumber = 7 * DAYS;
pub const Burn: Permill = Permill::from_percent(0);

pub const MaxApprovals: u32 = 30;
}

impl treasury::Config for Test {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureRoot<AccountId>;
type RejectOrigin = EnsureRoot<AccountId>;
type Event = Event;
type OnSlash = Treasury;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type MaxApprovals = MaxApprovals;
type BurnDestination = ();
type WeightInfo = ();
// TODO: add bounties?
type SpendFunds = ();
}

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Test>()
Expand All @@ -220,6 +253,7 @@ mod tests {

// Author gets 50% of tip and 50% of fee = 15
assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 15);
assert_eq!(Balances::free_balance(Treasury::account_id()), 15);
});
}

Expand All @@ -235,6 +269,7 @@ mod tests {

// Author gets 50% of tip and 50% of fee = 15
assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 0);
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
});
}

Expand All @@ -250,6 +285,7 @@ mod tests {

// Author gets 50% of tip and 50% of fee = 15
assert_eq!(Balances::free_balance(CollatorSelection::account_id()), 0);
assert_eq!(Balances::free_balance(Treasury::account_id()), 0);
});
}
}
25 changes: 22 additions & 3 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ mod types {

// Aura consensus authority.
pub type AuraId = sp_consensus_aura::sr25519::AuthorityId;

/// Council Instance
pub type CouncilInstance = collective::Instance1;
}

/// Common constants of statemint and statemine
mod constants {
use super::types::BlockNumber;
use super::types::{BlockNumber, AccountId, CouncilInstance, Balance};
use sp_runtime::Perbill;
use frame_support::weights::{Weight, constants::WEIGHT_PER_SECOND};
use frame_system::{EnsureOneOf, EnsureRoot};
use sp_core::u32_trait::{_1, _2};

/// This determines the average expected block time that we are targeting. Blocks will be
/// produced at a minimum duration defined by `SLOT_DURATION`. `SLOT_DURATION` is picked up by
/// `pallet_timestamp` which is in turn picked up by `pallet_aura` to implement `fn
Expand All @@ -73,14 +79,27 @@ mod constants {
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

// PICA = 12 decimals
pub const PICA: Balance = 1_000_000_000_000;
pub const MILLI_PICA: Balance = PICA / 1_000;
pub const MICRO_PICA: Balance = MILLI_PICA / 1_000;


/// We assume that ~5% of the block weight is consumed by `on_initialize` handlers. This is
/// used to limit the maximal weight of a single extrinsic.
// TODO changed to be more in line with statemine
pub const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
/// TODO: We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used by
/// Operational extrinsics.
pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

/// We allow for 0.5 seconds of compute with a 6 second average block time.
/// TODO: We allow for 0.5 seconds of compute with a 6 second average block time.
pub const MAXIMUM_BLOCK_WEIGHT: Weight = WEIGHT_PER_SECOND / 2;

/// Origin for either root or half of general council
pub type EnsureRootOrHalfCouncil = EnsureOneOf<
AccountId,
EnsureRoot<AccountId>,
collective::EnsureProportionAtLeast<_1, _2, AccountId, CouncilInstance>,
>;
}
17 changes: 13 additions & 4 deletions runtime/picasso/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "picasso-runtime"
version = "0.1.0"
edition = "2018"
description = "Picasso, Kusama Parachain Runtime Implementation"
authors = ["Seun Lanlege<seunlanlege@gmail.com>"]
authors = ["Seun Lanlege <seunlanlege@gmail.com>"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down Expand Up @@ -32,13 +32,17 @@ authorship = { package = "pallet-authorship", git = "https://github.com/parityte
balances = { package = "pallet-balances", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
indices = { package = "pallet-indices", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
randomness-collective-flip = { package = "pallet-randomness-collective-flip", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
pallet-collective = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false, optional = true }
collective = { package = "pallet-collective", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
membership = { package = "pallet-membership", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
scheduler = { package = "pallet-scheduler", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
session = { package = "pallet-session", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
sudo = { package = "pallet-sudo", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
timestamp = { package = "pallet-timestamp", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
treasury = { package = "pallet-treasury", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
democracy = { package = "pallet-democracy", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
transaction-payment = { package = "pallet-transaction-payment", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
oracle = { package = "pallet-oracle", path = "../../frame/oracle", default-features = false }
runtime-common = { path = "../common", default-features = false, version = "0.8.30" }
runtime-common = { path = "../common", default-features = false }
# Used for the node template's RPCs
system-rpc-runtime-api = { package = "frame-system-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
transaction-payment-rpc-runtime-api = { package = "pallet-transaction-payment-rpc-runtime-api", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.8", default-features = false }
Expand Down Expand Up @@ -95,6 +99,11 @@ std = [
"sudo/std",
"indices/std",
"oracle/std",
"treasury/std",
"democracy/std",
"scheduler/std",
"runtime-common/std",
"collective/std",
"transaction-payment/std",
"parachain-info/std",
"cumulus-pallet-aura-ext/std",
Expand All @@ -120,7 +129,7 @@ runtime-benchmarks = [
"balances/runtime-benchmarks",
"timestamp/runtime-benchmarks",
"oracle/runtime-benchmarks",
"pallet-collective/runtime-benchmarks",
"collective/runtime-benchmarks",
"collator-selection/runtime-benchmarks",
"session-benchmarking/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
Expand Down
Loading