Skip to content

Commit

Permalink
Add multisig and treasury pallets to the runtime (#249)
Browse files Browse the repository at this point in the history
* Add pallet multisig to the runtime

* Add pallet treasury to the runtime

* Implement DealWithFees to put fees into Treasury

* Update spec_version to 35

* Filter out treasury pallet calls except `spend` and `reject_approval` calls

---------

Co-authored-by: Alex Siman <[email protected]>
  • Loading branch information
F3Joule and siman authored Dec 28, 2023
1 parent bdf4d2b commit e25c7ce
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ fn parachain_genesis(
endowed_account: Some(root_key),
},
transaction_payment: Default::default(),
treasury: Default::default(),
}
}

Expand Down
8 changes: 8 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ frame-try-runtime = { git = "https://github.com/paritytech/substrate", default-f
pallet-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-session = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-sudo = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
Expand Down Expand Up @@ -121,12 +123,14 @@ std = [
"pallet-aura/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-multisig/std",
"pallet-collator-selection/std",
"pallet-session/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-xcm/std",
"parachain-info/std",
"polkadot-parachain/std",
Expand Down Expand Up @@ -178,7 +182,9 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-collator-selection/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down Expand Up @@ -213,12 +219,14 @@ try-runtime = [
"pallet-authorship/try-runtime",
"pallet-balances/try-runtime",
"pallet-collator-selection/try-runtime",
"pallet-multisig/try-runtime",
"pallet-proxy/try-runtime",
"pallet-insecure-randomness-collective-flip/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-utility/try-runtime",
"pallet-vesting/try-runtime",
"pallet-xcm/try-runtime",
Expand Down
80 changes: 74 additions & 6 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ use sp_version::RuntimeVersion;
use frame_support::{
construct_runtime, parameter_types,
dispatch::DispatchClass,
traits::{ConstU32, ConstU64, ConstU8, Contains, WithdrawReasons},
traits::{ConstU32, ConstU64, ConstU8, Contains, Currency, OnUnbalanced, WithdrawReasons},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight,
WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
},
PalletId,
};
use frame_support::traits::InstanceFilter;
use frame_support::traits::{Imbalance, InstanceFilter};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
EnsureRoot, EnsureWithSuccess,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
pub use sp_runtime::{MultiAddress, Perbill, Permill, FixedI64, FixedPointNumber};
pub use sp_runtime::{MultiAddress, Perbill, Percent, Permill, FixedI64, FixedPointNumber};
use xcm_config::{XcmConfig, XcmOriginToTransactDispatchOrigin};

use pallet_creator_staking::{CreatorId, EraIndex};
Expand Down Expand Up @@ -176,7 +176,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("subsocial-parachain"),
impl_name: create_runtime_str!("subsocial-parachain"),
authoring_version: 1,
spec_version: 34,
spec_version: 35,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 7,
Expand Down Expand Up @@ -278,8 +278,14 @@ impl Contains<RuntimeCall> for BaseFilter {
let is_force_transfer =
matches!(c, RuntimeCall::Balances(pallet_balances::Call::force_transfer { .. }));

let is_treasury_spend =
matches!(c, RuntimeCall::Treasury(pallet_treasury::Call::spend { .. }));
let is_remove_treasury_approval =
matches!(c, RuntimeCall::Treasury(pallet_treasury::Call::remove_approval { .. }));

match *c {
RuntimeCall::Balances(..) if is_set_balance || is_force_transfer => false,
RuntimeCall::Treasury(..) if !is_treasury_spend && !is_remove_treasury_approval => false,
_ => true,
}
}
Expand Down Expand Up @@ -372,13 +378,43 @@ parameter_types! {

impl pallet_transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// We process transaction fees with NativeOnChargeTransaction in the Energy pallet.
type OnChargeTransaction = Energy;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = WeightToFee;
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
}

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 10000 * UNIT;
pub const SpendPeriod: BlockNumber = 7 * DAYS;
pub const Burn: Permill = Permill::from_percent(0);
pub const TreasuryPalletId: PalletId = PalletId(*b"df/trsry");
pub const MaxApprovals: u32 = 10;
pub const MaxBalance: Balance = 10_000_000 * UNIT;
}

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = Balances;
type ApproveOrigin = EnsureRoot<AccountId>;
type RejectOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = ();
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type BurnDestination = ();
type SpendFunds = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>;
type MaxApprovals = MaxApprovals;
type SpendOrigin = EnsureWithSuccess<EnsureRoot<AccountId>, AccountId, MaxBalance>;
}

parameter_types! {
pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4);
Expand Down Expand Up @@ -606,6 +642,23 @@ impl pallet_utility::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const DepositBase: Balance = deposit(1, 88);
// Additional storage item size of 32 bytes.
pub const DepositFactor: Balance = deposit(0, 32);
}

impl pallet_multisig::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = ConstU32<100>;
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const MinDomainLength: u32 = 4;
pub const MaxDomainLength: u32 = 63;
Expand Down Expand Up @@ -721,6 +774,19 @@ impl pallet_account_follows::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
}

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
if let Some(mut fees) = fees_then_tips.next() {
if let Some(tips) = fees_then_tips.next() {
tips.merge_into(&mut fees);
}
// for fees and tips, 100% to treasury
Treasury::on_unbalanced(fees);
}
}
}

parameter_types! {
pub DefaultValueCoefficient: FixedI64 = FixedI64::checked_from_rational(1_25, 100).unwrap();
Expand All @@ -732,7 +798,7 @@ impl pallet_energy::Config for Runtime {
type Balance = Balance;
type DefaultValueCoefficient = DefaultValueCoefficient;
type UpdateOrigin = EnsureRoot<AccountId>;
type NativeOnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, ()>;
type NativeOnChargeTransaction = pallet_transaction_payment::CurrencyAdapter<Balances, DealWithFees>;
type ExistentialDeposit = ExistentialDeposit;
type WeightInfo = pallet_energy::weights::SubstrateWeight<Runtime>;
}
Expand Down Expand Up @@ -790,6 +856,7 @@ construct_runtime!(
// Monetary stuff.
Balances: pallet_balances = 10,
TransactionPayment: pallet_transaction_payment = 11,
Treasury: pallet_treasury = 12,

// Collator support. The order of these 5 is important and shall not change.
Authorship: pallet_authorship = 20,
Expand All @@ -801,6 +868,7 @@ construct_runtime!(
Vesting: pallet_vesting = 26,
Proxy: pallet_proxy = 27,
Utility: pallet_utility = 28,
Multisig: pallet_multisig = 29,

// XCM helpers.
XcmpQueue: cumulus_pallet_xcmp_queue = 30,
Expand Down

0 comments on commit e25c7ce

Please sign in to comment.