From 47bb08351a4559eb2d18bbbf986b127876e956bb Mon Sep 17 00:00:00 2001 From: Sergej Sakac <73715684+Szegoo@users.noreply.github.com> Date: Thu, 18 Apr 2024 18:35:54 +0200 Subject: [PATCH] Add utility pallets (#86) * add utility pallet * add multisig * add proxy * fmt * Update runtime/regionx/src/lib.rs Co-authored-by: cuteolaf * Update runtime/regionx/src/lib.rs Co-authored-by: cuteolaf * Update runtime/regionx/src/lib.rs Co-authored-by: cuteolaf --------- Co-authored-by: cuteolaf --- Cargo.lock | 3 ++ Cargo.toml | 3 ++ runtime/regionx/Cargo.toml | 12 ++++++ runtime/regionx/src/impls.rs | 47 ++++++++++++++++++++++- runtime/regionx/src/lib.rs | 72 +++++++++++++++++++++++++++++++++--- 5 files changed, 129 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aee179dd..c0d31cbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9336,11 +9336,14 @@ dependencies = [ "pallet-collator-selection", "pallet-ismp", "pallet-message-queue", + "pallet-multisig", + "pallet-proxy", "pallet-session", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-utility", "pallet-xcm", "parachains-common", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 7ece8be2..cda66da2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,9 @@ pallet-timestamp = { version = "27.0.0", default-features = false } pallet-transaction-payment = { version = "28.0.0", default-features = false } pallet-transaction-payment-rpc-runtime-api = { version = "28.0.0", default-features = false } pallet-message-queue = { version = "31.0.0", default-features = false } +pallet-multisig = { version = "28.0.0", default-features = false } +pallet-proxy = { version = "28.0.0", default-features = false } +pallet-utility = { version = "28.0.0", default-features = false } sp-api = { version = "26.0.0", default-features = false } sp-blockchain = { version = "28.0.0", default-features = false } sp-io = { version = "30.0.0", default-features = false } diff --git a/runtime/regionx/Cargo.toml b/runtime/regionx/Cargo.toml index 54f90845..583bd00c 100644 --- a/runtime/regionx/Cargo.toml +++ b/runtime/regionx/Cargo.toml @@ -46,11 +46,14 @@ pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } pallet-message-queue = { workspace = true } +pallet-multisig = { workspace = true } +pallet-proxy = { workspace = true } pallet-session = { workspace = true } pallet-sudo = { workspace = true } pallet-timestamp = { workspace = true } pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-utility = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -119,8 +122,11 @@ std = [ "pallet-collator-selection/std", "pallet-message-queue/std", "regionx-primitives/std", + "pallet-multisig/std", + "pallet-proxy/std", "pallet-session/std", "pallet-sudo/std", + "pallet-utility/std", "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", @@ -164,7 +170,10 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-message-queue/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-xcm/runtime-benchmarks", "parachains-common/runtime-benchmarks", @@ -194,8 +203,11 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-message-queue/try-runtime", + "pallet-multisig/try-runtime", + "pallet-proxy/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", + "pallet-utility/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", "pallet-xcm/try-runtime", diff --git a/runtime/regionx/src/impls.rs b/runtime/regionx/src/impls.rs index 55f0edca..a9ef7f6b 100644 --- a/runtime/regionx/src/impls.rs +++ b/runtime/regionx/src/impls.rs @@ -1,9 +1,10 @@ -use crate::{AssetId, Runtime}; +use crate::{AssetId, Runtime, RuntimeCall}; +use frame_support::traits::InstanceFilter; use orml_asset_registry::DefaultAssetMetadata; use orml_traits::asset_registry::AssetProcessor; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -use sp_runtime::DispatchError; +use sp_runtime::{DispatchError, RuntimeDebug}; #[derive( Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen, @@ -28,3 +29,45 @@ impl AssetProcessor> for CustomAssetProce Ok(()) } } + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + RuntimeDebug, + MaxEncodedLen, + scale_info::TypeInfo, +)] +pub enum ProxyType { + /// Fully permissioned proxy. Can execute any call on behalf of _proxied_. + Any, + /// Can execute any call that does not transfer funds or assets. + NonTransfer, + /// Proxy with the ability to reject time-delay proxy announcements. + CancelProxy, + // TODO: add more proxies in future related to coretime trading. +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => + !matches!(c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. }), + ProxyType::CancelProxy => + matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })), + } + } +} diff --git a/runtime/regionx/src/lib.rs b/runtime/regionx/src/lib.rs index e052bf7b..390293ab 100644 --- a/runtime/regionx/src/lib.rs +++ b/runtime/regionx/src/lib.rs @@ -553,6 +553,58 @@ impl pallet_collator_selection::Config for Runtime { type WeightInfo = (); } +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = pallet_utility::weights::SubstrateWeight; +} + +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); + pub const MaxSignatories: u32 = 100; +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = MaxSignatories; + type WeightInfo = pallet_multisig::weights::SubstrateWeight; +} + +parameter_types! { + // One storage item; key size 32, value size 8; . + pub const ProxyDepositBase: Balance = deposit(1, 40); + // Additional storage item size of 33 bytes. + pub const ProxyDepositFactor: Balance = deposit(0, 33); + pub const MaxProxies: u16 = 32; + // One storage item; key size 32, value size 16 + pub const AnnouncementDepositBase: Balance = deposit(1, 48); + pub const AnnouncementDepositFactor: Balance = deposit(0, 66); + pub const MaxPending: u16 = 32; +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyDepositBase; + type ProxyDepositFactor = ProxyDepositFactor; + type MaxProxies = MaxProxies; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = MaxPending; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = AnnouncementDepositBase; + type AnnouncementDepositFactor = AnnouncementDepositFactor; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime @@ -579,15 +631,20 @@ construct_runtime!( Aura: pallet_aura = 33, AuraExt: cumulus_pallet_aura_ext = 34, + // Handy utilities + Utility: pallet_utility = 40, + Multisig: pallet_multisig = 41, + Proxy: pallet_proxy = 42, + // XCM helpers. - XcmpQueue: cumulus_pallet_xcmp_queue = 40, - PolkadotXcm: pallet_xcm = 41, - CumulusXcm: cumulus_pallet_xcm = 42, - MessageQueue: pallet_message_queue = 43, + XcmpQueue: cumulus_pallet_xcmp_queue = 50, + PolkadotXcm: pallet_xcm = 51, + CumulusXcm: cumulus_pallet_xcm = 52, + MessageQueue: pallet_message_queue = 53, // ISMP - Ismp: pallet_ismp = 50, - IsmpParachain: ismp_parachain = 51, + Ismp: pallet_ismp = 60, + IsmpParachain: ismp_parachain = 61, } ); @@ -598,6 +655,9 @@ mod benches { [pallet_assets, Assets] [pallet_balances, Balances] [pallet_session, SessionBench::] + [pallet_multisig, Multisig] + [pallet_proxy, Proxy] + [pallet_timestamp, Utility] [pallet_timestamp, Timestamp] [pallet_sudo, Sudo] [pallet_collator_selection, CollatorSelection]